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

Martin Koroudjiev mrtndimitrov@REDACTED
Tue Sep 29 10:06:48 CEST 2015


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



More information about the erlang-questions mailing list