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 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.unadiff
  module demo

  pub measure Meter

- pub distance(d: Int of Meters) -> Int of Meter = d
+ pub distance(d: Int of Meter) -> Int of Meter = d

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

pub measure Meter

pub distance(d: Int of Meters) -> Int of Meter = d

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

pub measure Meter

pub distance(d: Int of Meter) -> Int of Meter = d