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) 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; 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), 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:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
See also
- Rule 5.1 Test
- Rule 5.3 Test
- Design rules
- Error codes
Source
The rule at commit af54ddad5:
docs/language-design.md:430(the design document)reqs/rules/RULE-0502.md(its traceability item)