Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Erlang generated with shadowed variables in bit patterns #3315

Open
lpil opened this issue Jun 22, 2024 · 0 comments · May be fixed by #3331
Open

Invalid Erlang generated with shadowed variables in bit patterns #3315

lpil opened this issue Jun 22, 2024 · 0 comments · May be fixed by #3331
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:high

Comments

@lpil
Copy link
Member

lpil commented Jun 22, 2024

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 lpil added bug Something isn't working help wanted Contributions encouraged good first issue Good for newcomers priority:high labels Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant