Rule 7.1
Chapter 7, Expressions and statements Test
An operator, a swizzle, an index, and a call must mean what WGSL’s typing table gives them. TypeScript’s == and != are accepted as aliases of the typed shader comparisons === and !==; no JavaScript coercion is emitted.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
Rule 1.1 applied to expressions.
Derives from
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:
the compile gate and src/core/oracle-backend-parity.test.ts; TS8003 for a matrix product whose dimensions do not meet (Rule 4.8, #169); TS8003 for an operator WGSL has no overload for on operands of one type, decided by kind in src/compiler/ts/lower/operator-kinds.ts (proposal 0008): arithmetic on a bool, a vector of bools, a struct or an array, + and - and every compound form on a matrix of doubles, an ordering on anything but a number or a vector of numbers, === and !== on a matrix, a struct or an array, &, | and ^ on a matrix, a struct or an array and ^ on a bool or a vector of bools (a float under any of the three is lowerBinary’s own TS8003, which keeps two whole numbers the front end folds, #236), unary - on a bool, a matrix, a struct or an array, unary + on a struct or an array, and any of them on a texture or a sampler, each sentence naming the operator and the type as written (Cannot + A: WGSL has no arithmetic on a struct. Write it field by field.), and the editor’s merge showing that sentence alone, without TypeScript’s TS2365, TS2362, TS2363 or TS2447 on the same operator, or its report about the number it types the result as, where that result is read in place, through a member or an element, or through a local declared from it (TS2322, TS2339, TS7053; Rule 12.4); pinned by src/compiler/ts/operators-statements.test.ts, which reads both halves, and src/language-service/service.test.ts.
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:
-
TS8003TYPE_MISMATCH - Two types that do not fit where they meet (an operator, a condition, a declaration, a return or an argument), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross or an f32 past its range.
See also
Source
The rule at commit 26de7be8:
docs/language-design.md:502(the design document)reqs/rules/RULE-0701.md(its traceability item)