gleam-lang / stdlib

🎁 Gleam's standard library
https://hexdocs.pm/gleam_stdlib/
Apache License 2.0
413 stars 152 forks source link

[erlang runtime] wrong output of `io.debug` and `string.inspect` for bit arrays #534

Closed clembu closed 3 months ago

clembu commented 3 months ago

The problem

import gleam/io

pub fn main() {
  io.debug(<<3>>)
}
// expected: <<3>>
// actual: ""

the above line outputs <<3>> in the language tour in the browser, but outputs a quoted empty string "" in the terminal when running on erlang with gleam run

System information

$ gleam --version
gleam 1.0.0

$ gleam deps list
gleam_stdlib 0.36.0
gleeunit 1.0.2

$ erl --version
Erlang/OTP 25 [erts-13.2.2.6] 
giacomocavalieri commented 3 months ago

That's expected, on the erlang target strings are represented as bit arrays, so whenever io.debug/string.inspect runs into that its best bet is to treat it as a String as it cannot know if it was a string or bit array in Gleam code.

If you need to print debug a bit array you could use the bit_array.inspect function.

lpil commented 3 months ago

Thank you