Repository navigation
Reject __proto__ as the JavaScript name of a field - #9513
Conversation
Why:
In JavaScript, __proto__ is an accessor every object inherits from
Object.prototype, not a plain key. A record field with that name is
written through the setter (#9457) and, when absent, reads the
prototype, and every code path that builds a record needs its own
workaround. The type checker now rejects the name (#9512).
Diagnostic added (__proto__ field name):
Example:
type t = {name: string, @as("__proto__") parent?: int}
After (diagnostic):
A field's JavaScript name can't be __proto__: in JavaScript, it sets the object's prototype instead of a property. Use another name, or a dict.
The check covers record and inline-record labels, plain or renamed
with @as, object-type fields (including those @obj externals
generate) and @tag. Object literals without a type annotation and
dict literals keep printing a "__proto__" key as a computed key.
Review: Why does the record spread lose its Object.defineProperty
branch? It only ran for a field named __proto__, which can't be
declared any more, so no program that compiles changes its output.
Breaking: A type declaring a field, object field or @tag with the
JavaScript name __proto__ no longer compiles. Rename the field with
@as, or use a dict for objects that have such a key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gL4qcnMmoKbamLEyfN
Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog💥 Breaking Change
Semantic Diff1 commit · Full page Reject __proto__ as the JavaScript name of a field9655a68 · cknitt + Claude · Dec 03, 2026, 06:57 UTC
Diagnostic added (__proto__ field name) type t = {name: string, @as("__proto__") parent?: int}
The check covers record and inline-record labels, plain or renamed with
Review
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9513 +/- ##
=======================================
Coverage 82.54% 82.54%
=======================================
Files 469 469
Lines 66224 66227 +3
=======================================
+ Hits 54666 54669 +3
Misses 11558 11558
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
Codex Review Summary: 🔄 RunningThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Closes #9512. Fixes #9457.
In JavaScript,
__proto__is an accessor that every object inherits fromObject.prototype, not a plain key. A field with that name is written through the setter and, when absent, reads the prototype. So each code path that builds or updates a record needed its own workaround.The type checker now rejects
__proto__as the JavaScript name of:@as(exception records included)@objexternal generates@tag, on the type or on a constructorObject literals without a type annotation and dict literals still compile, and still print
["__proto__"]as a computed key.Removed: the
Object.definePropertybranch for__proto__in record spreads (#9416) and its helperE.define_own_property, with the tests for it. This makes #9471 unnecessary. In #9460, only its__proto__part can go.New tests: four error snapshots in
tests/error_tests/single(plain field,@asfield, object field,@tag).🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gL4qcnMmoKbamLEyfN