fix(#774): resolve super.<prop> value form via parent vtable lookup - #780
Merged
Conversation
Value-form `super.<prop>` was lowered to `this.<prop>` in PR #754 (crates/perry-hir/src/lower/expr_misc.rs::lower_super_prop), so a child override silently shadowed the parent. Strict JS resolves the read through the parent's prototype. - Adds `Expr::SuperPropertyGet { property }` HIR variant; ident-form `super.foo` now lowers to it. Computed form `super[expr]` keeps the existing `this[expr]` fallback (out of scope; tracked as follow-up). - Codegen walks the parent class chain in `ctx.classes` / `ctx.methods`. When a parent declares a method named `<prop>`, materializes it as a closure value via `js_closure_alloc_singleton` mirroring `Expr::FuncRef`; otherwise returns `undefined`. - Emits closure-call wrappers for class instance methods alongside the existing `hir.functions` wrapper loop in `compile_module`, so the singleton allocator has a `__perry_wrap_<method>` to bind. Wrappers forward to `perry_method_<...>(this_box, args)` with `this=undefined`, matching strict-JS plain-invocation semantics for `const fn = super.greet; fn(arg)`. Call-form `super.method(args)` continues to route through `Expr::SuperMethodCall` unchanged, so the rxjs / NestJS canaries from PR #754 are unaffected. Adds `test-files/test_super_property_override.ts` as a parity test pinning the new behavior (expected: `undefined`).
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 #774. Value-form
super.<prop>was lowered tothis.<prop>in PR #754 (crates/perry-hir/src/lower/expr_misc.rs::lower_super_prop), so a child override silently shadowed the parent. Strict JS resolves the read through the parent's prototype.What changed
Expr::SuperPropertyGet { property }variant. Ident-formsuper.foolowers to it; computedsuper[expr]keeps itsthis[expr]fallback (out of scope here).Expr::SuperPropertyGetincrates/perry-codegen/src/expr.rs): walks the parent class chain inctx.classes/ctx.methods. When a parent declares a method<prop>, materializes it as a closure value viajs_closure_alloc_singleton(mirroringExpr::FuncRef); otherwise returnsundefined.__perry_wrap_<method>for every class instance method incompile_module, alongside the existinghir.functionswrapper loop. Forwards toperry_method_<…>(this_box, args)withthis=undefined, matching strict-JS plain-invocation semantics forconst fn = super.greet; fn(arg).Call-form
super.method(args)continues to route throughExpr::SuperMethodCallunchanged — the rxjs / NestJS canaries from PR #754 are unaffected.Validation
node --experimental-strip-types test-files/test_super_property_override.ts→undefined./target/release/perry test-files/test_super_property_override.ts -o /tmp/t && /tmp/t→undefined./run_parity_tests.sh --filter test_decorators— all NestJS decorator canaries from PR Add legacy TypeScript decorator metadata support #754 PASS (test_decorators_nest_js_common_canaryis a pre-existing compile failure unrelated to this PR)../run_parity_tests.sh --filter test_super/--filter test_inherit— all PASS.cargo fmt --checkTest plan
parityjob green.cargo-testgreen.