Home / Docs / Diagnostics
U2022: Integer literal does not fit its type
Release v0.4.0
An integer literal is outside the range of the type it takes.
Why Una rejects it
In edition 0.2, an integer literal takes the fixed-width type its context expects, such as an annotated let, a parameter, a field, a return or the other operand of an operator (spec/18 §2). A literal outside that type's range is U2022: U8 holds 0 to 255, I8 holds -128 to 127, and so on.
A computed value that may leave the range is not U2022 but an overflow obligation (spec/18 §3).
In requires, ensures and where clauses, literals are mathematical integers, so U2022 does not apply there.
How to fix it
- Write a literal that fits.
- Or give the value a wider type.
The repair at a glance
src/demo.una
module demo
- pub port() -> U16 = 70000
+ pub port() -> U16 = 8080Failing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub port() -> U16 = 70000Fixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub port() -> U16 = 8080