Rule 5.4
Chapter 5, Literals and typing Test
A literal must fit the type it takes; -1 in a u32 position and 2147483648 in an i32 position are refused as written.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
an out-of-range literal has no value in the type and would be a different number on the GPU.
Derives from
Literals (an integer literal must be representable in its type).
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 (surface §13, “the value has to fit”).
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
- Rule 5.3 Test
- Rule 5.5 Test
- Design rules
- Error codes
Source
The rule at commit af54ddad5:
docs/language-design.md:444(the design document)reqs/rules/RULE-0504.md(its traceability item)