From d3433ed0175df9bce5f9f1b9a9c25f3cddc2a189 Mon Sep 17 00:00:00 2001 From: James Clark Date: Sat, 22 Aug 2020 17:32:24 +0700 Subject: [PATCH] Add semantics for fail statement Fixes #337. --- lang/spec.html | 54 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/lang/spec.html b/lang/spec.html index 5f995756..0fa6b473 100644 --- a/lang/spec.html +++ b/lang/spec.html @@ -6127,14 +6127,20 @@

Statement execution

describes how each kind of statement is evaluated, assuming that the evaluation of those expressions and actions completes normally, and assuming that the execution of any substatements does not cause termination of the current worker. - Except where explicitly stated to the contrary, statements handle abrupt -completion of the evaluation of expressions and actions as follows. If in the -course of executing a statement, the evaluation of some expression or action -completes abruptly with associated value e, then the current worker is -terminated with termination value e; if the abrupt termination is a check-fail, -then the termination is normal, otherwise the termination is abnormal. If the -execution of a substatement causes termination of the current worker, then the -execution of the statement terminates at that point. +Except where explicitly stated to the contrary, statements handle abrupt +completion of the evaluation of expressions and actions as follows. There are +two possibilities. +

+ +

+If the execution of a substatement causes termination of the current worker, +then the execution of the statement terminates at that point.

On fail clause
 class="grammar">stmt-with-on-fail := regular-compound-stmt on-fail-clause
 on-fail-clause := on fail typed-binding-pattern statement-block
 
+

+A stmt-with-on-fail is executed by executing the +regular-compound-stmt. A check expression or action, +or a fail statement may cause control to transfer to the +on-fail-cause. In this case, the typed-binding-pattern +is matched to the associated error value, binding the variables occurring within +the typed-binding-pattern; the statement-block is then +executed with these bindings in scope. Otherwise, the +on-fail-clause is not executed. +

+

+The static type of the associated error value is determined from the static type +of the relevant check expressions and actions, and +fail statements. It is a compile error unless the match of the +typed-binding-pattern with the associated error value is guaranteed +to succeed by the static type of the associated error value. +

@@ -7502,6 +7525,17 @@

Fail statement

fail-stmt := fail expression ;
 
+

+Executing a fail-stmt will cause control flow to transfer to the on-fail-clause +of the nearest lexically enclosing statement that has an on-fail-clause. If +there is no such statement, it terminates the current worker. +

+

+The static type of the expression must be a subtype of error. Execution of the +fail-stmt evaluates the expression; the resulting error value is passed to the +on-fail-clause or becomes the termination value of the current worker. +

+
@@ -8623,6 +8657,10 @@

Summary of changes from 2020R1 to Swan Lake

parameter can always be specified by name as well as position; a parameter cannot be declared as public.
  • Local type definitions have been removed.
  • +
  • The fail statement has been added, along with a on +fail clause for compound statements. If a check expression +or action fails, it behaves like a fail statement rather than a +return statement.