---
title: "Rule 5.2: Literals and typing, a TypeShade design rule"
description: "Rule 5.2 of the TypeShade language design, in Literals and typing. A written number beside a typed peer in an arithmetic operator or a builtin call must take…"
url: https://typeshade.dev/reference/rules/5-2/
language: en
---

# Rule 5.2

Chapter 5, Literals and typing Test

A written number beside a typed peer in an arithmetic operator or a builtin call must take the peer’s kind; a written number beside an `f64` or an `f64` vector must become an `f64` literal carrying the full double. A read of a constant of no fixed type ([Rule 5.1](https://typeshade.dev/reference/rules/5-1/)) must take the peer’s kind as the written number does, the full double beside an `f64` included.

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

## Rationale

a literal has no type of its own until something states one, and the peer is the nearest statement.

## Derives from

[Overload Resolution](https://gpuweb.github.io/gpuweb/wgsl/#overload-resolution-section); surface §13 (the `min(1, i)` edge).

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

`retargetLit` in `src/compiler/ts/numeric.ts` (the lift is guarded on `isF64(peer) || isVec64(peer)`, PR [#166](https://github.com/typeshade/typeshade/issues/166)), so `x + 0.1` and `min(x, 0.1)` on an `x: f64` both carry the pair `(0.10000000149011612, -1.4901161415892261e-9)`; `src/compiler/ts/int-lit-coerce.test.ts` and `int-lit-context.test.ts` (the `min(1, i)` case); `src/compiler/ts/f64-types.test.ts` (`lifts a literal beside an f64 and a declared f64 const`) for the double; `src/compiler/ts/abstract-const.test.ts` for a constant of no fixed type (`const C = 0.1` and `const K = 7; x * (K / 3)` beside an `f64`).

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

- [`src/compiler/ts/abstract-const.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/abstract-const.test.ts#L1)
- [`src/compiler/ts/abstract-const.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/abstract-const.ts#L1)
- [`src/compiler/ts/f64-types.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/f64-types.test.ts#L1)
- [`src/compiler/ts/int-lit-coerce.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/int-lit-coerce.test.ts#L1)
- [`src/compiler/ts/int-lit-context.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/int-lit-context.test.ts#L1)
- [`src/compiler/ts/int-lit-range.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/int-lit-range.test.ts#L1)
- [`src/compiler/ts/numeric.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/numeric.ts#L1)

## Explained in

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

- [§13 Integer literals](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#13-integer-literals)

## See also

- [Rule 5.1](https://typeshade.dev/reference/rules/5-1/) Test
- [Rule 5.3](https://typeshade.dev/reference/rules/5-3/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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