Home / Docs / Diagnostics
U2029: An invalid unit declaration or unit expression
Release v0.4.0
A unit declaration or a unit expression is invalid.
Why Una rejects it
A unit is declared with measure (ADR 0104):
- a base unit by its name;
- a derived unit by an expression of declared units and positive integer factors, as
measure Kilometer = 1000 * Meter.
A unit expression names only declared units, a derived unit does not refer to itself, and one with no base unit and scale 1 is refused, since it would be no unit at all.
of follows only a number type: an integer type or F64, and in edition 0.5 (preview) F32, Decimal[s], Complex[F64] and Complex[F32].
The repair at a glance
src/demo.una
module demo
pub measure Meter
- pub distance(d: Int of Meters) -> Int of Meter = d
+ pub distance(d: Int of Meter) -> Int of Meter = dFailing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
pub measure Meter
pub distance(d: Int of Meters) -> Int of Meter = dFixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
pub measure Meter
pub distance(d: Int of Meter) -> Int of Meter = d