Repository navigation
Class values for @cpp classes implemented here; local class field initializer reading a local - #743
Merged
Merged
Conversation
… initializer reading a local - A @cpp class implemented here (methods with bodies) is a value: `new k(n)` through it makes an object with C++'s vtable, as `new` of the class does. It has no rtti, so the value's identity is its vtable, which each such class has of its own. A @cpp class whose objects C++ makes has no `.new` or constructor here: "the @cpp class 'X' can't be used as a value: its objects are made by C++". - `function f(start) { class C { v = start; } }` was "'ts.Load' op using value defined outside the region". The discovery pass of a constructor of a class declared in a function is given its field initializers with its body, so the read is found and reported as a member's is: "a member of class 'C' reads 'start', a local of the function the class is declared in". A top-level class's are not given to it (its `fn = () => this.prop` stopped resolving `this`). - Tests: 00cpp_class_values (gc, rc, none, own), cpp_class_value_error, class_field_capture_error; the verifier skips the two errors. The design doc §5 says so. 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 follow-ups to classes as values (#742).
@cpp classes implemented here as values
@cppclass whose methods have bodies (it implements C++ methods) can be atypeofvalue.new k(n)through the value makes an object whose vtable has C++'s layout, asnewof the class does.@cppclasses have no rtti, so==compares the vtable, which each such class has of its own.@cppclass whose objects C++ makes has no.newor constructor here, so it is now an error: "its objects are made by C++".@cppclasses have no statics, so onlynewand==go through such a value.A local class's field initializer reading a local
function f(start: number) { class C { v = start; } }was "'ts.Load' op using value defined outside the region". It now reports "a member of class 'C' reads 'start', a local of the function the class is declared in", as a method that reads a local already does.fn = () => this.prop.Tests
00cpp_class_values(gc, rc, none, own),cpp_class_value_errorandclass_field_capture_error. The ownership verifier skips the two error tests.Found on the way, not fixed (both on main too)
new A().fn()withfn = () => this.propis "not a function to call".-mm=own, an arrow field that readsthisis an escaping-closure error.🤖 Generated with Claude Code