Repository navigation
An imported boxed object is the exporter's object, not a copy - #726
Merged
Merged
Conversation
… an error
`{ count: 0, inc() { this.count = this.count + 1; } }` cast to an
interface with `count: number` was given a clone with `count` widened to
f64, while `inc` kept writing the s32 layout into it: `c.count` read
4.94066e-324 after one call, in every model.
The cast of an object with methods to an interface now reports an error
when a field it would convert is one the object's members name through
`this` (or they use `this` otherwise), naming the field and both types and
suggesting `0.0` or `<number>0`. MLIRGen records those names for each
object literal's storage (recordObjectLiteralThisFields); an object from
another module has no record, so any method of it counts. Objects whose
methods never name the field (00interface_object5) and objects of fields
only are still cloned, with the warning.
export_object_literal_untyped now gives `count: 0.0`, and its importer
asserts the count read through the interface.
Tests: 00interface_method_object_field_type,
interface-cast/method_object_narrow_field.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An untyped object literal with methods is exported boxed: its global holds a pointer to the object (@boxed in the declarations). The importer loaded that pointer and then copied the whole object into its own variable, so `A.counterObj` in the importer was a snapshot: its method calls and writes never reached the exporter's object, and a cast to an interface copied the snapshot again (`c.inc()` left `A.counterObj.count` behind). The importer's variable is now the pointer itself, an object type, as the exporter's is. import_object_literal_untyped asserts the count read through the import and through a function of the exporter after the interface's call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-copy # Conflicts: # tslang/test/tester/tests/export_object_literal_untyped.ts # tslang/test/tester/tests/import_object_literal_untyped.ts
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.
An untyped object literal with methods is exported boxed: the exporter's global holds a pointer to the object, and the declarations say
@boxed let counterObj : {count:number, inc(): void}. The importer loaded that pointer and then copied the whole object into its own variable (MLIRGenVariables.cpp, theisBoxedpath). SoA.counterObjin the importer was a snapshot:A.countOf(), the exporter's own read, stayed at 0);c.inc(),c.countwas 3 andA.counterObj.countwas 2.The importer's variable is now the pointer itself (an object type), the same as the exporter's. Field reads, method calls and interface casts all reach the one object.
import_object_literal_untypednow asserts the count three ways after the interface's call: through the interface, through the import, and through a function of the exporter. It runs as compile and JIT, under gc, rc and none.Validated on Windows: ctest 6210/6210; DefaultLib release passes under gc (175), rc and none (174 + 1 gc-only skip), own (164 + 11 not-own skips).
Not changed: a variable declared with a type literal (
const t: { count: number, inc(): void } = ...) is a value in this language. Assigning it, passing it, storing it in an array and casting it to an interface all copy it, by design.🤖 Generated with Claude Code