gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Invalid Erlang generated with shadowed variables in bit patterns

Open lpil opened this issue 2 weeks ago • 0 comments

pub fn go(code) {
  let pre = 1
  case code {
    <<pre:bytes-size(pre), _:bytes>> -> pre
    _ -> panic
  }
}

Generates this invalid Erlang:

go(Code) ->
    Pre = 1,
    case Code of
        <<Pre@1:Pre@1/binary, _/binary>> ->
            Pre@1;

        _ ->
            erlang:error(#{gleam_error => panic,
                    message => <<"panic expression evaluated"/utf8>>,

                    function => <<"go"/utf8>>,
                    line => 5})
    end.

Note how Pre@1 is being used for the size, not Pre.

lpil avatar Jun 22 '24 15:06 lpil