Home / Docs / Diagnostics
U0102: Clause out of order or repeated
Release v0.4.0
U0102 reports a clause placed after a clause that must follow it, and a repeated fails, derived from, accepts, if error or if none clause.
Why Una rejects it
- The clauses of a function header follow one canonical order: every
requires, then everyensures, then everyuses, then at most onefails, then at most onederived from(spec/02 §3). - Capability operations follow the same idea: every
requires, then everyensures, then at most onefails, then at most oneaccepts(spec/02 §4). - The handling clauses of a statement come in the order
if error, thenif none, each at most once (spec/06 §3).
A fixed order lets people and tools find each part of a contract at a glance.
A fails or derived from clause is not repeated: a function or operation fails with a single error kind (ADR 0006), and one derived from lists all its requirements.
The repair at a glance
diff
module demo
pub double(x: Int) -> Int
- ensures result == x * 2
requires x >= 0
+ ensures result == x * 2
=
x * 2Failing example
una
module demo
pub double(x: Int) -> Int
ensures result == x * 2
requires x >= 0
=
x * 2Fixed example
una
module demo
pub double(x: Int) -> Int
requires x >= 0
ensures result == x * 2
=
x * 2