variable propagation in try

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

variable propagation in try

Peti Gömöri-2
Hello,

I understand that passing variables between different blocks of a try catch expression is mostly unsafe, because in case of expressions it is not guaranteed that the variable binding actually happened.

But why using a variable in a clause after "of" that is bound in the block after "try" is marked as unsafe by the compiler?
For example:

```
f() ->
    try
        {A, B} = a:b(),
        A
    of
        ok ->
            B %% unsafe ???
    catch _:_ ->
            a:b()
    end.
```

thanks
Peter

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: variable propagation in try

Richard Carlsson-3
If I recall correctly, it was initially decided to keep the set of safe variables conservative when try/catch was added. It could be relaxed to allow this case.


        /Richard

2018-06-28 12:08 GMT+02:00 Peti Gömöri <[hidden email]>:
Hello,

I understand that passing variables between different blocks of a try catch expression is mostly unsafe, because in case of expressions it is not guaranteed that the variable binding actually happened.

But why using a variable in a clause after "of" that is bound in the block after "try" is marked as unsafe by the compiler?
For example:

```
f() ->
    try
        {A, B} = a:b(),
        A
    of
        ok ->
            B %% unsafe ???
    catch _:_ ->
            a:b()
    end.
```

thanks
Peter

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions