Home / Docs / Diagnostics
U2040: A statement after stop or skip in the same block, which never runs
Release v0.4.0
A statement comes after stop or skip in the same block, so it never runs.
Why Una rejects it
In edition 0.4, stop ends the innermost loop and skip ends the current iteration (spec/26 §3, ADR 0116 rule 6). A statement after an unconditional stop or skip in the same block can never run, which is almost always a mistake: the statement was meant to come before the exit, or under a condition. The checker refuses it, at the first such statement.
stop when c is conditional, so statements after it run whenever c is false and stay legal.
Statements after the block that holds the stop or skip, such as those after an if whose block ends in skip, run on the other paths and stay legal too.
How to fix it
The repair removes the statements after the exit.
The repair at a glance
src/demo.una
module demo
pub positives(xs: List[Int]) -> Int
=
let edit count = 0
for x in xs
if x <= 0
skip
- count = count - 1
count = count + 1
countFailing example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub positives(xs: List[Int]) -> Int
=
let edit count = 0
for x in xs
if x <= 0
skip
count = count - 1
count = count + 1
countFixed example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub positives(xs: List[Int]) -> Int
=
let edit count = 0
for x in xs
if x <= 0
skip
count = count + 1
count