What is the semantics of returning from a block inside guaranteed blocks?

Suppose we have the following sequence of methods:

m1 self m2: [^1] m2: block self m3: block. Processor := nil "crash!" m3: block [block value] ensure: [^2] 

The question is, what is the value of anObject m1 ?

In other words, is semantics [Λ†2] defined as a guaranteed block? Two possibilities are possible:

  • Returns from blocks are ignored in guaranteed blocks : in this case, m1 will return from 1 .
  • The return from the block is carried out in guaranteed blocks . In this case, the image will be split.

Please note that I am not asking what will happen. I'm rather interested in defining a thread of execution.


EDIT

Corollary 1 (as Lucas confirmed in his answer below): Not a good programming style!

+6
source share
1 answer

Check out page 23 of the Draft of ANSI Smalltalk Standard project, which describes the return statement and its interaction with ensure: blocks::

If the evaluation of the completion block completes with the return statement, the result is undefined.

+4
source

Source: https://habr.com/ru/post/980739/


All Articles