[erlang-questions] variable exported from case in OTP 18

Theepan vasdeveloper@REDACTED
Tue Sep 29 12:07:30 CEST 2015


The difference is implicit vs explicit. When it is explicit compiler
assumes you are aware of what you are doing and you control the return
value of each case clause.

Theepan

On Tue, Sep 29, 2015 at 1:36 PM, Martin Koroudjiev <mrtndimitrov@REDACTED>
wrote:

> Hello,
>
> I am confused why this code generates warning with the warn_export_vars
> option:
>
> -module(test).
>
> -export([test/1]).
>
> test(Mode) ->
>     case Mode of
>         r -> {ok, FP} = file:open("warn.erl", [read]);
>         w -> {ok, FP} = file:open("warn.erl", [write])
>     end,
>     file:close(FP).
>
> compile:file("test.erl", [report, warn_export_vars]).
> test.erl:10: Warning: variable 'FP' exported from 'case' (line 6)
> {ok,test}
>
> Why this is better than this code:
>
> test(Mode) ->
>     {ok, FP} =
>         case Mode of
>             r -> file:open("warn.erl", [read]);
>             w -> file:open("warn.erl", [write])
>         end,
>     file:close(FP).
>
> which produces no warnings?
>
> Thanks in advance.
>
> Regards,
> Martin
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150929/0a6d1fe5/attachment.htm>


More information about the erlang-questions mailing list