Fix wrong code generation for this-> in lambda type parameters#4955
Open
SeanTAllen wants to merge 1 commit intomainfrom
Open
Fix wrong code generation for this-> in lambda type parameters#4955SeanTAllen wants to merge 1 commit intomainfrom
this-> in lambda type parameters#4955SeanTAllen wants to merge 1 commit intomainfrom
Conversation
Lambda types like `{(this->A!): Bool}` are desugared into anonymous
interfaces during the sugar pass. The desugaring preserved `this->`
verbatim, but inside the generated interface, `this` refers to the
interface's own receiver rather than the enclosing class's receiver.
This semantic mismatch caused incorrect structural subtype checks,
leading to wrong vtable dispatch, incorrect results, or segfaults
when the lambda was forwarded to another function.
The fix resolves `this->` to the enclosing method's receiver cap
during lambda type desugaring. Since the compiler already enforces
that `this->` can only appear in `box` methods, `{(this->A!)}` now
correctly desugars to `{(box->A!)}`.
Closes #4168
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.
When a lambda type contains
this->(e.g.,{(this->A!): Bool}), the sugar pass desugars it into an anonymous interface. The desugaring preservedthis->verbatim, but inside the generated interface,thisrefers to the interface's own receiver rather than the enclosing class's receiver. This caused incorrect structural subtype checks, leading to wrong vtable dispatch, incorrect results, or segfaults when the lambda was forwarded to another function rather than called directly.The fix resolves
this->to the enclosing method's receiver cap during lambda type desugaring, so{(this->A!)}in aboxmethod correctly becomes{(box->A!)}.Closes #4168