Home / Docs / Diagnostics

U4002: Implicit flow through control, failure or call under raised pc

Release v0.4.0

A failure, a call or a policy call appears inside a branch on a labeled value, where the program counter does not allow it. The message names the construct and the label; its related location is the condition. In a program that starts tasks, U4002 also reports a check point that data above internal decide.

Why Una rejects it

Inside the branches of an if, when or if none on a labeled value, the program counter carries that label (spec/07 §3). A failure there would reveal which branch ran, so:

(Edition 0.3, ADR 0094 rule 7.)

When the label comes from the answer of an operation that its binding labels with gives, the message and the first repair name that binding and operation, as "the answer of @service_files.owner, labeled internal[Service]", and the call is a related location.

In a program that starts tasks (edition 0.4, spec/27 §8 rule 5), the schedule moves from one task to the next after a count of check points: calls of Una code, operations, loop iterations and the elements that map, filter, first_where and fold visit. A check point that data above internal decide would let that data order the tasks' later prints and trace events. Such a check point is, for example, a call inside a branch on a secret value, a loop whose bound is secret, a map over a secret list or a call of a function value chosen by a secret value. So it is U4002 in a package:

So is a call of a generic function or of first_where, or of code the label rules do not check, whose function argument returns such data, and a tasks at most n at once whose n is such data.

The rule is coarse: a branch whose two sides pass as many check points is refused too.

Data at internal, as the requests of HttpServer, are not refused, so they can still order the effects of started tasks, a known residual (#1708). una report lists each such check point in information.timing as a task switch at internal.

How to fix it

Code that must branch on labeled data returns a labeled value instead of failing.

When the label comes from the answer of an operation that its binding labels with gives:

In a program that starts tasks:

The repair at a glance

diff
  module demo

- kind PinError = | Rejected
-
- pub check(pin: secret Int) -> secret Int
-   fails PinError
- =
-   if pin == 1234
-     1
-   else
-     fail Rejected
+ pub check(pin: secret Int) -> secret Bool = pin == 1234

Failing example

una
module demo

kind PinError = | Rejected

pub check(pin: secret Int) -> secret Int
  fails PinError
=
  if pin == 1234
    1
  else
    fail Rejected

Fixed example

una
module demo

pub check(pin: secret Int) -> secret Bool = pin == 1234