Semantic Diff

#9513 Reject __proto__ as the JavaScript name of a field

1 commit

0a686a9a9b6787ea4fcdb1e08dc70fd9d5760a66..pr-9513

9655a683f · cknitt + Claude · Dec 03, 2026, 06:57 UTC

Reject __proto__ as the JavaScript name of a field

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).

addedDiagnostic __proto__ field name

type t = {name: string, @as("__proto__") parent?: int}
diagnostic
After
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.