Rule 5.1
Chapter 5, Literals and typing Test
An integer-written literal must take the integer type the position around it declares. An unannotated function-local let or const initialized by such a literal takes i32 or u32 when declared uses require that one type for the local: direct calls to declared, nongeneric functions, constructor and instance or static method arguments, and explicitly typed initialization or simple assignment. A simple assignment can take the type of its destination or of a right-hand side that declares its type independently of the local. Resolve the local, callee and receiver by their declarations, including through nested scopes and inherited members; an override supplies its own signature. A concrete member parameter independent of generic arguments can establish a demand; an unresolved generic parameter or circular inference cannot. Conflicting concrete scalar types must be refused with an annotation or cast remedy. Where no integer type is established, the literal must be an f32.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
this is WGSL’s abstract-integer rule narrowed to the positions where a type is stated, and the f32 default is the surface’s history rather than WGSL’s rule.
Derives from
Abstract Numeric Types and Conversion Rank; surface §13.
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:
src/compiler/ts/lit-coerce.ts, src/compiler/ts/local-numeric-inference.ts, src/compiler/ts/local-numeric-inference.test.ts, src/compiler/ts/int-lit-context.test.ts, and int-lit-coerce.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:
See also
- Rule 4.8 Test
- Rule 5.2 Test
- Design rules
- Error codes
Source
The rule at commit 26de7be8:
docs/language-design.md:341(the design document)reqs/rules/RULE-0501.md(its traceability item)