Rule 5.4
On this page

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 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:

TS8003 TYPE_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:

Edit this page Report a problem