Skip to content

x.name and x[k] = v of a value of type any; a write of an optional interface field with no place throws - #942

Merged
ASDAlexander77 merged 3 commits into
mainfrom
any-name-set-own
Nov 19, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
any-name-set-own

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

x.name and x[k] = v (+=, ++) of a value of type any, read and written at run time through the keys adapter of #940 (new op ANY_KEYS_OP_SET). Follow-up to the 11-19 ruling.

What works (gc, rc, none)

  • x.name of x: any is x["name"]. The member probe (evaluatePropertyValue) still finds nothing on any, because i in a asks it about length.
  • x[k] = v, x.name = v, += and ++ write through the adapter. A plain = does no read first, so a getter doesn't run.
  • TypeError cases:
    • a key the type doesn't have (no key is added);
    • a method;
    • an accessor with no setter;
    • a tuple or object-literal key (the any holds a copy);
    • a value of the wrong kind for a number, string or boolean key or element. Before, "hi" silently became 0.
  • Arrays are written in range or one past the end.
  • s[i] of a string in an any is now a string (it was a char).
  • Not any-specific: writing an optional interface field to an object made without it (const i: I = { n: 1 }; i.o = "a") stored through a null address and crashed. It now throws.

-mm=own: still the clear compile error. The own variant (copyable keys only) was tried and reverted inside this PR: its adapters failed own's borrow checks in the default library (the Error classes) and in 00any_to_interface.ts, so they broke programs that never read a key.

Tests:

  • New: 00any_keys_write.ts.
  • Removed: the any_key_assign, any_key_compound and any_key_increment error tests, which now compile.

Checked locally

  • Full ctest: 8,464 passed, 0 failed.
  • tsc sweep against 1119e: 0 pass→fail, 44 fail→pass.
    • One sweep test, arrayConcatMap.ts, now crashes instead of failing with an error. The crash is older than this PR: boxing an element of [].concat([1]) into any crashes the older compiler too. The test reaches it now that b.a compiles.
  • Default-library tests (clean Bug fixes - this scope for params #108 clone, rebuilt): gc, rc and none pass.
  • wasm32 tester suite: none 703/0, rc 702/0, own 573/0.
  • rc/own/gc leak probes stay flat from 50k to 800k iterations.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits November 19, 2026 21:25
…(ANY_KEYS_OP_SET); a write of an optional interface field an object has no place for throws

- `x.name` of `x: any` is `x["name"]`, read at run time; the member probe (evaluatePropertyValue) still finds none on `any`, as `i in a` asks it of `length`
- `x[k] = v`, `x.name = v`, `+=` and `++` write through the adapter: a plain `=` makes no read (a getter does not run); a key the type has not got, a method, an accessor with no setter, a tuple's key (the `any` holds a copy) and a value not of a number, string or boolean key's kind are TypeErrors; an array is written in range or one past its end
- `s[i]` of a string in an `any` is a string, as in JavaScript (it was a char)
- `i.o = v` of an interface whose object was made without the optional field `o` stored through a null address: it throws

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r a key whose value copies

Under own a key's value is read as a copy in a box of its own and written as a copy of the value, so a key
holding a number, a boolean, a string or an `any` is read and written through `any`; one holding an object
is a TypeError on read and write (it would be a second owner), as is a write through an interface and an
array grown through `any` (own can't prove the unboxed value alive across them). `in` asks of every key.
The adapters unbox where they use the value under own. Test 00any_keys_models.ts runs under every model;
the own compile errors for x[k] and k in x are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wn failed own's checks in the default library (Error classes, an interface holding a method) and in 00any_to_interface.ts, where they reached programs that never read a key; own keeps its clear error

This reverts commit b57b5b0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit c07c10e into main Nov 19, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the any-name-set-own branch November 19, 2026 22:30
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