Skip to content

perry-codegen: String.startsWith 2-arg form (with position) unsupported #315

Description

@proggeramlug

What happened

Perry's codegen rejects the standard ES String.prototype.startsWith(searchString, position) 2-arg form with:

perry-codegen: String.startsWith expects 1 arg, got 2

Surfaced compiling effect/src/String.ts (func 19) during the #309 compat sweep.

What you expected

MDN spec for String.prototype.startsWith: the 2-arg form is standard and widely used. Perry should accept either arity.

Minimal reproduction

const s = "abcdef";
console.log(s.startsWith("cd", 2));   // expected: true
console.log(s.startsWith("ab", 0));   // expected: true
perry compile repro.ts -o /tmp/out
# fails with: perry-codegen: String.startsWith expects 1 arg, got 2

Likely fix site

crates/perry-codegen/src/lower_string_method.rs — search for startsWith arm. Should mirror what slice / substring already do for optional second arg (default to 0 when absent, lowering to a js_string_starts_with_at(s, prefix, pos) runtime call).

String.prototype.endsWith(s, endPosition) likely has the same gap and should be fixed in the same change — worth a grep for endsWith expects in the codebase.

Environment

  • Perry version: 0.5.405
  • Host OS: macOS 26.4 (arm64)
  • Target: native
  • Effect version: 3.21.2 (where this surfaced)

Discovered as part of the #309 long tail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions