Home / Docs / Diagnostics

U2034: stop or skip outside a loop body, or across a task boundary

Release v0.4.0

A stop or skip is outside a loop body, or across a task boundary from its loop.

Why Una rejects it

In edition 0.4, stop ends the innermost for loop around it, stop when c does so when c holds, and skip ends the current iteration and goes on to the next (spec/26 §3, ADR 0116 rule 6). Each belongs to the body of its innermost loop. It is an error:

A loop inside the task is a loop for them.

How to fix it

To end a task's work early:

The repair at a glance

src/demo.unadiff
  module demo

  pub doubled(xs: List[Int]) -> List[Int]
  =
    together for x in xs
      if x < 0
-       skip
-     x + x
+       0
+     else
+       x + x

Failing example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub doubled(xs: List[Int]) -> List[Int]
=
  together for x in xs
    if x < 0
      skip
    x + x

Fixed example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub doubled(xs: List[Int]) -> List[Int]
=
  together for x in xs
    if x < 0
      0
    else
      x + x