Repository navigation
A cast helper in a namespace, union widening, own's instanceOf and a returned union parameter (TSLANG 44-46) - #803
Merged
Conversation
…returned union parameter (TSLANG 44-46) 44: the helpers a cast makes from source (___cast, ___unbox, ...) are declared in the root namespace; the one made before is now erased there too, so code in a namespace no longer gets the helper made for another type (`flag && a && b` threw "Can't cast from union type"). 45: a union widened to one that has all its members is a plain cast, not a ___cast call whose result -mm=own took for a value stored. -mm=own takes a class's ..instanceOf called through the vtable for a call that destroys nothing, an exported class's too. 46 (-mm=own): a function returning its union parameter, given a new object, freed it twice. The temporary taken over is the object behind its views, and its release may be in a block only the call leads to. `x instanceof A` of a borrowed union is a test that keeps nothing. 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.
Fixes TSLANG_ISSUES 44, 45 and 46, found while porting native_ts_graphics (
examples/nri/variable_shading_nri.ts).44:
flag && a && bin a namespace threw "Can't cast from union type"The helpers a cast builds from source (
___cast,___unbox,___unbox_interface,___check_tuple,___bin_op_*,___union_eq_*) are declared in the root namespace, butremoveGenericFunctionMaperased the previous one only from the namespaces it walked: insideNSit stopped atNS. The stale___cast(made fornull | boolean | A) was then instantiated fornull | boolean | A | B, and aBreached itsthrow. The previous helper is now erased from the root namespace.45:
-mm=ownrefusedflag && a && bof two classests.Cast(the lowering already re-tags it), not a___castcall whose result own treated as a stored value.___casttests an instance with its class's..instanceOfthrough the vtable (ThisVirtualSymbolRef). For an exported class (every class in a namespace) own resolved that as an open family and assumed it may destroy anything, so!this.cleared && texture && descriptorwas refused. A class's..instanceOfis the compiler's own and destroys nothing, as the.instanceOfslot read already was.46:
-mm=ownfreed a returned union parameter twicefunction same(v: A | null): A | null { return v; }called assame(new A()): the compiled exe hung or crashed at exit (alpha121: 0xC0000374); JIT passed.<A | null>new A(), a view with no release, so it made the result fresh while the object's own release stayed. It now looks at the object behind its views.x instanceof Aof a borrowed union was refused, as it already was for a field read (const x = this.f; x instanceof A). The cast to an opaque pointer whose vtable is read for.instanceOfis now a test that keeps nothing in the borrow walk, asisBorrowalready said.Tests
00tslang_issue_44.ts,00tslang_issue_45.ts,00tslang_issue_46.ts, JIT and compiled under gc, rc, none and own.🤖 Generated with Claude Code