Rule 7.4
Chapter 7, Expressions and statements Test
A shift amount the compiler can fold must be in 0 to 31; a divisor the compiler can prove to be zero must be refused where the division is lowered.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
WGSL takes a shift amount modulo the bit width and makes a const-expression amount at or past it a shader-creation error, and makes a const-expression divisor of zero a shader-creation error, giving x only where the divisor is not known before shader execution; a program Tint refuses should not compile, and a divisor that is certainly zero or an amount certainly past the width is most likely a mistake. A run-time amount takes WGSL’s answer on every target (Rule 11.12). A run-time divisor takes it too where an operand has a declared integer type: ii / (ii + 3) with ii: i32 is ii where ii + 3 is 0. Where no operand has a declared type and a position that states an integer type reads the quotient (Rule 5.1), a divisor that is zero at run time gives TypeScript’s value, 0. It does not give WGSL’s x / 0 = x (the owner’s decision of 2026-11-17, Amendment A8 of change 0134).
Derives from
Bit Expressions (the concrete shift rows); Arithmetic Expressions; surface §22 (#71, #68).
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:
TS8003 TYPE_MISMATCH from src/compiler/ts/lower/expression.ts, where lowerBinary folds a shift amount through foldConstNumber (src/compiler/ts/loop-bound.ts) and a divisor through divisorIsZero; src/compiler/ts/lower/statement.ts (lowerBitwiseAssignOp) for a compound shift assignment; and foldsToZero in src/compiler/ts/module-const.ts, which refuses a module const whose initializer divides by a proven zero; pinned by src/compiler/ts/shift-amount.test.ts and src/compiler/ts/zero-divisor.test.ts.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
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), a read of an optional value (
T | undefined,T | nullorT | null | undefined) that no test narrowed (Rule 7.10), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, anf32past its range or a builtin call outside its domain, such asMath.pow(-2., 2.).
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:688(the design document)reqs/rules/RULE-0704.md(its traceability item)