Give type-literal method members an implicit this param so annotated objects keep their receiver - #258
Merged
Merged
Conversation
…iteral annotations
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
A type-literal annotation with a METHOD member (
inc(): void,MethodSignature) mapped to a bare this-lessFunctionType, unlike an inferred object literal (func<object<...>>) or an interface method (func<opaque,...>). Casting a method-bearing literal to such an annotation dropped the receiver ("losing this reference"), and calls through the annotated value passed garbage asthis:Fix (three parts)
getTupleFieldInfo(MLIRGenTypes.cpp):MethodSignaturemembers now get an implicit opaquethisfirst param — the same convention already used for interface method funcTypes.isBoundReferencethen triggers on field access, binding the receiver from the base object, identical to how inferred object literals already behave.MLIRPrinter::printFuncType: skip an opaque/object-typed first input when printing function types — it's the implicitthis, not declarable in source syntax ("Opaque" doesn't parse back), mirroringDeclarationPrinter::printParamswhich already omitsthis. Keeps the cross-module@dllimportdeclaration round-trip intact.CastLogicHelper: only warn"losing this reference"when the targetFunctionTypehas nothisslot of its own — a target that keeps the opaquethisparam loses nothing (the receiver is re-bound at each property access).Test plan
New regression test
00object_annotated_method.ts(global + local annotated vars, mutating and reading methods), registered in both compile and jit modes.Full ctest suite: 724/724 passed (722 existing + 2 new).
🤖 Generated with Claude Code