Branch Does Not Get Canceled

Summary

After the 10 seconds sleep, the branch expression is not getting canceled

OnBegin<override>()<suspends> : void =
    block:
        branch:
            loop:
                Print("Branch")
                Sleep(1.0)
        Sleep(10.0)
    Sleep(Inf)

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Verse

Steps to Reproduce

Run the code above

Expected Result

The branch expression should get canceled after the 10 seconds.

Observed Result

The branch expression continues to run (“Branch” continues to be printed).

Platform(s)

PC

Additional Notes

If the OnBegin finishes [when removing Sleep(Inf)], the branch gets canceled.

We have so many issues with structured concurrency related to defer and branch :frowning:
Also excluding the fact that it is confusing and hard to remember specifically each case if is a bug or intendeed…

Can you place defer statements inside that branch and the block, to check if they run?

Defer and Branch should have the same “scope rules” as mentioned on this page above.

OnBegin<override>()<suspends> : void =
    block:
        defer. Print("Hello 1")
        branch:
            defer. Print("Hello 2")
            loop:
                Print("Branch")
                Sleep(1.0)
        Sleep(10.0)
        defer. Print("Hello 3")
    Sleep(Inf)

It should print:

Branch
Branch
[...]
Branch
Hello 2
Hello 3
Hello 1

If defer prints but branch is kept running, then I have no idea. If the defer does not print, something is wrong with the way the verse handles the logic :frowning:

Tried here. Hello 2 never gets printed and the branch loop continues to run after the 10 seconds

FORT-1133207 has been ‘Closed’. This is working as intended by design.

This is confusing, why does defer consider blocks a new enclosing scope, but branch does not?

We have issues for so long related to these conflicts. On the past, different epic devs also gave different answers when me and others made related questions.
Looks like there is no common consensus about how they should work…

This section on the book talking about scopes was made after a talk that I had with the language devs related to these complains, with the goal of making clear and easy to consult if we get confused by it.

In a perfect scenario, we would be able to “attach” the defer/branch to where we want (function scope, block scope, etc). But we can’t do that, and when we make bug reports of it about both behaviors, they get both closed which is clearly weird. How can they be both “correct” and both “wrong” at same time?

2 Likes