---
title: "Rule 12.6: Diagnostics, a TypeShade design rule"
description: "Rule 12.6 of the TypeShade language design, in Diagnostics. A requirement the front end can check must be checked at the front end, in the author's words…"
url: https://typeshade.dev/reference/rules/12-6/
language: en
---

# Rule 12.6

Chapter 12, Diagnostics Test

A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

## Rationale

WGSL checks each requirement at the earliest opportunity, and for TypeShade the earliest opportunity is the source line.

## Derives from

[Errors](https://gpuweb.github.io/gpuweb/wgsl/#errors) (“each requirement will be checked at the earliest opportunity”); surface §3 and §7.

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

[`TS8029`](https://typeshade.dev/reference/errors/ts8029/), [`TS8031`](https://typeshade.dev/reference/errors/ts8031/), [`TS8036`](https://typeshade.dev/reference/errors/ts8036/), [`TS8038`](https://typeshade.dev/reference/errors/ts8038/), [`TS8068`](https://typeshade.dev/reference/errors/ts8068/), and the rest of the front-end codes, among them [`TS8002`](https://typeshade.dev/reference/errors/ts8002/) for a type the file declares nowhere, which used to be emitted as a struct of that name for Tint to refuse (`src/compiler/ts/unknown-names.test.ts`); the requirements proposal 0008 moved forward from Tint: a `for` update the lowering does not count, refused instead of dropped with its loop ([Rule 7.5](https://typeshade.dev/reference/rules/7-5/)), an operator WGSL has no overload for on its operands’ kind ([Rule 7.1](https://typeshade.dev/reference/rules/7-1/)), a vector of bools in a uniform or storage binding ([Rule 6.8](https://typeshade.dev/reference/rules/6-8/)), a decorator nothing reads, `@group` and `@binding` on a declaration among them ([Rule 6.7](https://typeshade.dev/reference/rules/6-7/)), a barrier, a derivative or a `workgroupUniformLoad` after a non-uniform `break` or `continue` ([Rule 8.5](https://typeshade.dev/reference/rules/8-5/)), and a `while` condition that is not a `bool` (Rule 7.5), each pinned where that rule’s Enforced-by names it, and a loop’s hidden counter, which an author’s `_w` or `_i` reached ([Rule 2.2](https://typeshade.dev/reference/rules/2-2/)), pinned by `src/compiler/ts/loop-shapes.test.ts`; two constant expressions Tint refused, now folded as a divisor is and refused with [`TS8003`](https://typeshade.dev/reference/errors/ts8003/): a `clamp` whose bounds cross (`src/compiler/ts/clamp-bounds.test.ts`, [#373](https://github.com/typeshade/typeshade/issues/373)) and an `f32` value past the range (`src/compiler/ts/f32-const-range.test.ts`, [#374](https://github.com/typeshade/typeshade/issues/374)); the debts of Appendix B are the requirements not yet moved forward.

The files that verify it at commit af54ddad5, each at the first line that names the rule:

- [`src/compiler/ts/array-minmax-types.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/array-minmax-types.test.ts#L1)
- [`src/compiler/ts/clamp-bounds.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/clamp-bounds.test.ts#L1)
- [`src/compiler/ts/compute-stage-reachability.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compute-stage-reachability.test.ts#L1)
- [`src/compiler/ts/const-call-domain.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/const-call-domain.test.ts#L1)
- [`src/compiler/ts/f32-const-range.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/f32-const-range.test.ts#L1)
- [`src/compiler/ts/honest-refusals-tuples.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals-tuples.test.ts#L1)
- [`src/compiler/ts/honest-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/honest-refusals.test.ts#L1)
- [`src/compiler/ts/index-bound.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/index-bound.test.ts#L1)
- [`src/compiler/ts/io-attribute-arguments.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/io-attribute-arguments.test.ts#L1)
- [`src/compiler/ts/loop-shapes.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/loop-shapes.test.ts#L1)
- [`src/compiler/ts/lower/runtime-array.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/runtime-array.ts#L1)
- [`src/compiler/ts/module-vars-atomic.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-vars-atomic.test.ts#L1)
- [`src/compiler/ts/runtime-array-values.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/runtime-array-values.test.ts#L1)
- [`src/compiler/ts/struct-cycle.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/struct-cycle.test.ts#L1)
- [`src/compiler/ts/switch-validation.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/switch-validation.test.ts#L1)
- [`src/compiler/ts/unknown-names.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/unknown-names.test.ts#L2)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§3 Entries — stage attributes and explicit builtins](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#3-entries--stage-attributes-and-explicit-builtins)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8002`](https://typeshade.dev/reference/errors/ts8002/) `UNKNOWN_TYPE`**

A type name that nothing declares, in a parameter, a type argument, an alias, an `implements` clause or a base class, or a type that this surface does not take where the mapper reads one ([Rule 2.1](https://typeshade.dev/reference/rules/2-1/)). A base that the file declares and does not collect as a struct is `STRUCT_FIELD`.

**[`TS8003`](https://typeshade.dev/reference/errors/ts8003/) `TYPE_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 | null` or `T | null | undefined`) that no test narrowed ([Rule 7.10](https://typeshade.dev/reference/rules/7-10/)), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, an `f32` past its range or a builtin call outside its domain, such as `Math.pow(-2., 2.)`.

**[`TS8029`](https://typeshade.dev/reference/errors/ts8029/) `STRUCT_FIELD_MISSING_ATTR`**

A user-defined input of a compute entry: a parameter, or a field of its struct, that carries no `builtin<…>`. A compute entry has no user-defined input in WGSL, so the front end refuses it. On a vertex or fragment entry a value with no attribute is user-defined, and the compiler gives it its location ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)).

**[`TS8031`](https://typeshade.dev/reference/errors/ts8031/) `RECURSION`**

A call cycle: a function that reaches itself, directly or through other functions. WGSL has no call stack, so the compiler refuses the cycle before a target sees it.

**[`TS8036`](https://typeshade.dev/reference/errors/ts8036/) `MATH_ARGUMENT`**

A math builtin called with arguments that its signature does not take: two shapes that had to agree (`dot(vec3, vec2)`), an element kind that the builtin has no form for (`sin` on an integer vector), a scalar where a vector is due (`normalize(s)`), or a factor, exponent, offset or count of the wrong type. The message names the offending argument and, where one is short, the fix: splat the scalar, cast one side, or give the vectors one size.

**[`TS8038`](https://typeshade.dev/reference/errors/ts8038/) `F64_ENTRY_IO`**

An emulated double (`f64` or a `vec64`) on an entry's IO boundary: a `@location` parameter, a `@location` field of an IO struct or an entry's return. A double is a pair of `f32` words after lowering, and a varying interpolates each word on its own. Narrow with `f32(x)`, or read the double in the stage that needs it, since a uniform or a storage binding carries an `f64`.

**[`TS8068`](https://typeshade.dev/reference/errors/ts8068/) `RESERVED_NAME`**

`eval` or `arguments` bound by a variable, a parameter or a function, which ECMAScript's strict mode, and TypeScript with it, lets no declaration do (Rule 2.1).

## See also

- [Rule 12.5](https://typeshade.dev/reference/rules/12-5/) Test
- [Rule 12.7](https://typeshade.dev/reference/rules/12-7/) Test
- [Rule 2.2](https://typeshade.dev/reference/rules/2-2/)
- [Rule 6.7](https://typeshade.dev/reference/rules/6-7/)
- [Rule 6.8](https://typeshade.dev/reference/rules/6-8/)
- [Rule 7.1](https://typeshade.dev/reference/rules/7-1/)
- [Rule 7.5](https://typeshade.dev/reference/rules/7-5/)
- [Rule 8.5](https://typeshade.dev/reference/rules/8-5/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:1758`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L1758) (the design document)
- [`reqs/rules/RULE-1206.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-1206.md) (its traceability item)
