gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
18.19k stars 768 forks source link

Invalid Erlang generated for pipe expression in bit array size segment #3944

Open richard-viney opened 1 day ago

richard-viney commented 1 day ago

This Gleam code that uses a pipe in a size bit array segment:

pub fn main() {
  <<<<0xAE>>:bits-size(5 |> identity)>>
}

fn identity(x) {
  x
}

Produces this error output from gleam build on Gleam 1.6.2:

  Compiling bit_array_test
/Users/richardviney/Code/bit_array_test/src/bit_array_test.gleam:8:39: syntax error before: ','
/Users/richardviney/Code/bit_array_test/build/dev/erlang/bit_array_test/_gleam_artefacts/bit_array_test.erl:4:2: function main/0 undefined
%    4| -export([main/0]).
%     |  ^

/Users/richardviney/Code/bit_array_test/src/bit_array_test.gleam:6:2: spec for undefined function main/0
%    6|   <<<<0xAE>>:bits-size(5 |> identity)>>
%     |  ^

error: Shell command failure

There was a problem when running the shell command `escript`.

The generated Erlang code is here: bit_array_test.erl.txt


I'm uncertain whether pipes in bit array segments are meant to work, but blocks and case expressions work so pipes probably should too.

lpil commented 1 day ago

Ah! Yes, this is a bug. It should work and not generate invalid Erlang here.