Rule 8.9
On this page

Rule 8.9

Chapter 8, Functions and entry points Test

Method dispatch must be static, and a generic function or class must be compiled once per set of type arguments the program uses (Rule 3.9). A derived class value may occupy a base-typed position when its base view is proved read-only and dispatch-equivalent: every base-visible method or accessor has the same body on the concrete class, no receiver writes or receiver escape are lost, and the projected fields cannot observably change through an alias after construction. The proof is conservative across the compiled source; unknown receivers and unproved alias writes do not establish safety. Arguments, initializers, assignments, returns and contextual composite elements use the same conversion. A generated function takes the concrete value once and constructs its base representation, preserving effects and source evaluation order. A view that needs runtime override selection or receiver retention remains refused with the concrete type to keep; no general dynamic-dispatch restriction is imposed by WGSL itself. A class with no instance fields remains a constructible value, including method-only, static-only, inherited, mixin and generic classes. Its authored field list remains empty; GPU lowering provides an internal carrier without adding source members or inherited fields. A body a class inherits is compiled again for that class; what fails only there (a call that takes the base, a static the class does not have) must be refused when a function that is not a class’s own reaches it through calls, and must not be when nothing does, the body being dropped with every function that calls it.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

this representation settles generic arguments and concrete receiver classes during compilation. A read-only base projection is accepted only when it preserves that receiver’s behavior; a value requiring runtime selection needs a retained concrete representation and generated dispatch.

Derives from

Functions (“each user-defined function only has one overload”); surface §26, §30, §32 (design #92).

How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

TS8035 CLASS_MEMBER and examples/generic-class.shade.ts; src/compiler/ts/class-syntax.test.ts for a body a class inherits that fails for it alone, said when a call reaches it and dropped when none does. Read-only base views and unsafe overrides, accessors, receiver writes and alias mutation are pinned by src/compiler/ts/class-upcasts.test.ts; journeys/class-upcasts/ holds the packed package’s material constructor and factory evaluation order to independent JavaScript.

The files that verify it at commit 26de7be8, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit 26de7be8:

Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

TS8035 CLASS_MEMBER
A class member shape the surface does not take, or a use of a member the class rules refuse, and a new that builds no class (Rule 8.13).

See also

Source

The rule at commit 26de7be8:

Edit this page Report a problem