Skip to content

perry-codegen: string self-append: local 441 not in scope on Effect's internal/channel.ts #319

Description

@proggeramlug

What happened

Single module fails compilation with an internal-codegen error from the string self-append fast-path:

Error compiling module 'node_modules/effect/src/internal/channel.ts': lowering closure func_id=263:
  lowering closure body func_id=263: string self-append: local 441 not in scope

The error message comes from crates/perry-codegen/src/lower_string_method.rs (or wherever the s += t self-append optimization lives). The HIR transform that hoists or rebinds locals is producing a LocalGet(441) that the codegen-side scope lookup can't resolve.

What you expected

The lowering should either resolve the local through the same mechanism LocalGet uses everywhere else, or fall through to the slow path s = s + t when the optimization can't safely apply.

Why this is happening

Likely the same class as #318 (closure-collector misses arms): a HIR transform pass (closure-capture rewrite, generator transform, async-to-generator, inliner) is renumbering or hoisting locals, and the string self-append fast-path's scope lookup is the wrong walker — i.e. it's looking at the closure's own locals but the rewritten id lives in a parent / sibling scope.

Likely fix site

crates/perry-codegen/src/lower_string_method.rs — search for "string self-append". The fast path likely has its own ad-hoc scope-resolution logic that needs to consult the same scope chain LocalGet uses. Safe interim: when the scope lookup fails, fall through to the generic s = s + t slow path with an internal-warn trace rather than aborting compile.

Minimal reproduction

Same scratch project as #309. Single isolated repro is non-trivial — internal/channel.ts is a 1500+ LOC module and func 263 is one of many. The right approach is probably to land #318 first (which is the broader walker class) and see if this error persists; if it does, file a focused TS repro then.

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