Home / Docs / Diagnostics
U3025: if error clause on an expression that cannot fail
Release v0.4.0
An if error clause is on an expression that cannot fail.
Why Una rejects it
In edition 0.3, an if error clause belongs only where the expression can fail (spec/06 §3, ADR 0100). A clause on an expression that cannot fail never runs:
- arithmetic;
- a call of a function without
fails; - an operation without
fails; - or anything wrapped in
attempt, which already turns the failure into a value.
It also misleads the reader, and a dead if error fail V in a private function gives that function an error kind of its own, which every caller then has to handle.
The rule waits while the package has an error that can hide a failure: an error outside U3007, U3008 and U3009, or one inside the function that is called.
Editions 0.1 and 0.2 accept the clause.
How to fix it
Remove the clause. una fix applies this repair.
The repair at a glance
src/demo.una
module demo
kind LookupError = Missing | Unavailable
pub next(n: Int) -> Int
fails LookupError
=
let x = n + 1
- if error fail Unavailable
xFailing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
kind LookupError = Missing | Unavailable
pub next(n: Int) -> Int
fails LookupError
=
let x = n + 1
if error fail Unavailable
xFixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
kind LookupError = Missing | Unavailable
pub next(n: Int) -> Int
fails LookupError
=
let x = n + 1
x