fix: closes #655 — Array methods on Map.get(...).field chained access - #657
Merged
Conversation
…ss (v0.5.782) `m.get(k)!.pending.shift()` returned garbage and never mutated; `field.length = N` was silently ignored. Codegen's `static_type_of` for `PropertyGet` only consulted `ctx.classes`, so interface-typed receivers (`s: State` where `State` is a TS `interface`) failed the array-fast-path gate and fell into generic property dispatch. - Thread `interfaces: HashMap<String, perry_hir::Interface>` through `CrossModuleCtx` and `FnCtx` (six instantiation sites). - `static_type_of` falls back to `ctx.interfaces.get(...)` after a class miss and walks the `extends` chain. - Add `splice` arm to `lower_array_method.rs` so chained `.splice()` doesn't hit the silent return-receiver fallback. Repro byte-identical to Node for `shift` / `pop` / `slice` / `splice` / `length=`. 27/28 gap-suite tests pass (same baseline; 1 pre-existing failure unrelated). 225/225 perry-runtime unit tests pass. (Originally committed as v0.5.775 [ea921e02] but lost in a parallel-session hard-reset to origin/main; cherry-picked here with version bumped to v0.5.782 since v0.5.775..v0.5.781 are now occupied on origin.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #655. Under
perry compile, callingArray.prototypemethods on an array reached throughMap.get(k)!.fieldreturned garbage and never mutated forshift/splice/pop/slice/unshift, andfield.length = Nwrites were silently ignored. Aliasing to a single-identifier local first dispatched correctly.Root cause
crates/perry-codegen/src/type_analysis.rs::static_type_of'sPropertyGetarm only consultedctx.classes. TSinterfaces live inhir.interfaces, nothir.classes, so a receiver typeds: State(whereStateis an interface withpending: number[]) failed theis_array_exprgate. The call fell into generic property+call dispatch, which has no idea how to invokeArray.prototypeon a NaN-boxed array handle.pushwas special-cased elsewhere and accidentally worked; everything else didn't.Changes
interfaces: HashMap<String, perry_hir::Interface>throughCrossModuleCtxandFnCtx(six instantiation sites).static_type_offalls back toctx.interfaces.get(...)after a class miss, walks theextendschain.splicearm tolower_array_method.rsso chained.splice()doesn't hit the silent return-receiver fallback when the new array fast-path engages.Test plan
shift/pop/slice/splice/length=(test-files/issue_655_repro.ts).test_gap_console_methods, is the pre-existing timing-sensitive divergence).cargo test --release -p perry-runtime --lib: 225/225 pass.Out of scope (filed separately)
unshiftreturns the array instead of the new length. Pre-existing on the bare-local path that already worked. Filed as AOT:Array.prototype.unshiftreturns the array instead of the new length #656.interfacesmap is local-module-only; works for the issue's repro sinceStateis local. Follow-up.