GetFirefly/firefly

Variable bound inside of function call used in case is not in scope in clauses

KronicDeth opened this issue · 0 comments

encode_jer({choice,Choices},{Alt,Value}) ->
    case is_map_key(AltBin = atom_to_binary(Alt,utf8),Choices) of
        true ->
            EncodedVal = encode_jer(maps:get(AltBin,Choices),Value),
            #{AltBin => EncodedVal};
        false ->
            exit({error,{asn1,{invalid_choice,Alt,Choices}}})
    end;

from https://github.com/lumen/otp/blob/ca83f680aab717fe65634247d16f18a8cbfc6d8d/lib/asn1/src/asn1rtt_jer.erl#L113-L120

Errors with

stderr:    Compiling /Users/runner/work/lumen/otp/lib/asn1/src/asn1rtt_jer.erl
error: could not resolve variable
    ┌─ /Users/runner/work/lumen/otp/lib/asn1/src/asn1rtt_jer.erl:116:46
    │
116 │             EncodedVal = encode_jer(maps:get(AltBin,Choices),Value),
    │                                              ^^^^^^ not bound in scope

error: could not resolve variable
    ┌─ /Users/runner/work/lumen/otp/lib/asn1/src/asn1rtt_jer.erl:117:15
    │
117 │             #{AltBin => EncodedVal};
    │               ^^^^^^ not bound in scope

error: parsing failed

      Failed /Users/runner/work/lumen/otp/lib/asn1/src/asn1rtt_jer.erl

It appears the Erlang/BEAM allow AltBin to be bound inside the argument to is_map_key as the argument to case and then used in the clauses, but EIR does not.