What's the semantics of return from block inside ensured blocks?
Asked Answered
M

1

6

Assume 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's the value of anObject m1?

In other words, is the semantics of [ˆ2] well defined as an ensured block? There are two possibilities:

  1. The return from block is ignored in ensured blocks: In this case m1 will return with 1.
  2. The return from block is honored in ensured blocks: In this case the image will crash.

Please note that I'm not asking what will happen. I'm rather interested in the definition of the execution flow.


EDIT

COROLLARY 1 (as confirmed by Lukas in his answer below): Not a good programming style!

Michellmichella answered 9/1, 2015 at 1:12 Comment(0)
C
5

Check page 23 of the Draft of ANSI Smalltalk Standard that describes the return statement and its interaction with ensure: blocks:

If the evaluation of a termination block concludes with the execution of a return statement the result is undefined.

Chromium answered 9/1, 2015 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.