Skip to main content

UnguardedFail

rascal-0.34.0

Synopsis

Use of fail statement outside a condtional context.

Description

A fail statement is only allowed inside conditional statements. This error is generated when fail is used outside a conditional context.

Remedies:

  • Surround the fail statement by a conditional conditional statement.
  • Replace the fail statement by a Throw statement.
  • replace the fail statement by a Return statement.

Examples

Here is a correct (albeit not very useful) use of fail where the pattern match int N := 35 acts as guard:

rascal>if(int N := 35){ if(N > 10) fail; }
ok

Any condition (non only one using pattern matching) can act as guard:

rascal>if(true) { fail; }
ok

An error occurs when fail is used outside a conditional context:

rascal>fail;
|prompt:///|(0,5,<1,0>,<1,5>): Use of fail outside a conditional context
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UnguardedFail|
ok