Skip to content

own: lazily cached fields, @final methods (TSLANG 47, 48); escaping-capture use error; boolean assignment errors - #846

Merged
ASDAlexander77 merged 3 commits into
mainfrom
fix-fn-or-null-and-boolean-assign
Nov 14, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
fix-fn-or-null-and-boolean-assign

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

TSLANG_ISSUES 47: a lazily cached field returned through a local (-mm=own)

let r = this.cached; if (!r) { r = new Q(); this.cached = r; } return r; now compiles and runs under own.

  • The getter: before the facts, a read of a local that provably holds what a field holds is read as the field (OwnershipSignatureFieldLocals.cpp). So return r is return this.cached. The const-check form and r = n after this.cached = n work the same way.
  • The caller: a store into a field tested empty on the way (!f, == null, === undefined, else of if (f)) frees nothing (fillsEmptyField). A getter that only fills drops nothing, so a second call no longer ends the first result's borrow.
  • What stays a drop: the store still counts when there's a loop in between, when the test reads another field, or when a call in between may write the field. Such a call is judged by facts that count every fill as a drop, so a fill-only callee can't clear it.
  • Diagnostics: a folded const is named under --di, and the 'another variable' placeholder is gone.

TSLANG_ISSUES 48: @final methods

  • A method can be @final. It can't be overridden or be abstract, and calls run that method: directly, or through the vtable with the one callee known when its class is imported.
  • The -shared declaration printer writes @final.
  • Under own, a borrow ended by a call to an overridable method gets a note naming the method and pointing at @final.
  • Also fixed: a precedence slip in dropsInBody counted a store into a number field as a drop.

From the earlier session on this branch

  • -mm=own: using an object after an escaping closure captured it by copy is an error. A closure stored once into a field of the object it captures is a back-reference and borrows it.
  • (() => T) | null fields and locals now work.
  • Assigning a boolean to a number or a string, or a number to a boolean, is an error, as in tsc.
  • TSLANG_ENABLE_LTCG CMake option for the compiler's own targets (MSVC Release, off by default).

Still open

Item 49 is filed: three reduced own errors from powder_sandbox. A method that no module overrides is still taken as overridable when its class is exported. @final on accessors is accepted but does nothing yet.

Tests

  • New regression tests:
    • 00tslang_issue_47.ts and 00tslang_issue_48.ts, under every model.
    • Cross-module pairs own_lazy_cache_* and own_final_method_*, under every model, JIT and compiled.
    • Five own_err_* cases.
    • final_method_*_error.ts.
  • ctest: Release, Windows, all pass except 3 disabled tests.
  • DefaultLib (clean clone of main, rebuilt with this compiler): tests.ps1 passes for own, rc, gc and none.
  • Not run: WSL/Linux.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits November 14, 2026 00:59
…oolean assignment errors

- -mm=own: an object a `const` names, captured by copy by a closure that escapes, is the closure's
  from the capture on; a later use is "captured by a closure that escapes, and is still used here".
  A closure stored once into a field of the object it captures is a back-reference and borrows it.
- `(() => T) | null` fields and locals: the closure is the function value itself.
- Assigning a boolean to a number or a string, or a number to a boolean, is an error, as in tsc.

The CMake registrations and the shared ownership-facts helpers these use are in the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TSLANG 47, 48)

TSLANG 47 (-mm=own): `let r = this.cached; if (!r) { r = new Q(); this.cached = r; } return r;`
- Before the facts, a read of a local where it provably holds what a field holds is read as the
  field (OwnershipSignatureFieldLocals.cpp): a local declared from the field, or given a value just
  moved into it. The local's first value, read by nothing then, is dropped.
- A store into a field tested empty on the way (`!f`, `f == null`, `f === undefined`, the else of
  `if (f)`) frees nothing (fillsEmptyField). The signature pass decides each fill once, judging a
  call in between by facts that count every fill as a drop, and pins it on the release.
- Diagnostics name a folded const under --di; "another variable" is gone.

TSLANG 48: a method can be @Final. It can't be overridden or be abstract, a call of it runs it
(directly, or through the vtable with the one callee known when imported), and the -shared
declaration printer writes it. Under own, a borrow ended by a call of an overridable method gets a
note naming the method and pointing at @Final.

Also: dropsInBody's `!releasesNothing(r) && a || b` counted a store into a number field as a drop.

Item 49 (three reduced own errors from powder_sandbox) is filed open in TSLANG_ISSUES.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Release, off by default)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant