Repository navigation
A class field's function type inferred from its initializer works - #616
Merged
Merged
Conversation
Two class-field bugs with no interface involved: - `fn = () => 0` was stored as a plain function, which has no room for a closure's context: assigning a capturing closure to it later warned "losing this reference" and the call crashed (0x80000003). A field whose function type is inferred is now stored as a hybrid function, as an annotated `fn: () => int` field and a `let` (adjustLocalVariableType) are. - `fn = this.m` had no type in the discovery pass: the fields are laid out before the methods are declared, so the field became `any` there and `w.fn()` failed with "not a function to call" before the real pass ran. Such a field now holds its place and is typed again once the members are declared (mlirGenClassRetypeFields); the code made against the placeholder is thrown away with the pass. The real pass already typed it as the bound method. The field type computation moved into mlirGenClassDataFieldType so both places share it. 00class_function_typed_field_inferred.ts covers both forms, reassignment, a closure over the bound-method field and the interface path of #612, under gc AOT/JIT and the rc/none corpus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 19, 2026
CMakeLists.txt: both sides added a test at the same place; both kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Two class-field bugs with no interface involved, found while landing #612.
1.
fn = () => 0then a capturing closurewarned "losing this reference" and crashed (0x80000003). The field's type was inferred from the initializer as a plain
!ts.func, which has no room for a closure's context. A field whose function type is inferred is now stored as a hybrid function, as an annotatedfn: () => intfield and alet(adjustLocalVariableType) already are.2.
fn = this.mfailed with "not a function to call". The real pass types the field as the bound method, but the discovery pass lays out the fields before it declares the methods, so the field was
anythere and the call failed before the real pass ran. In a discovery pass such a field now holds its place and is typed again once the members are declared (mlirGenClassRetypeFields). Code emitted against the placeholder is thrown away with the pass.The field type computation moved into
mlirGenClassDataFieldTypeso that both places use it.Tests
00class_function_typed_field_inferred.tscovers both forms, reassignment (including a closure replacing the bound method) and the interface path from #612. It runs under gc AOT/JIT and in the rc/none corpus. Before the fix it failed in all 6 modes; it now passes in all of them. Fullctest -C Releasepasses: 4736/4736.These also work: a class used before its declaration, a class local to a function, and
fn = this.mnaming an inherited method. Under-mm=rc --verify-ownershipthe test produces no diagnostics.🤖 Generated with Claude Code