elixir-lang/elixir

`:io.get_line` returns binary in Elixir and charlist in Erlang

Closed this issue · 3 comments

Elixir and Erlang/OTP versions

~ % elixir --version
Erlang/OTP 28 [erts-16.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Elixir 1.18.4 (compiled with Erlang/OTP 28)
~ % erl --version
Erlang/OTP 28 [erts-16.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V16.0.2 (press Ctrl+G to abort, type help(). for help)

Operating system

DragonFlyBSD

Current behavior

In Erlang (from erl):

is_binary(io:get_line("")). #=> false

In Elixir (from iex):

is_binary(:io:get_line("")) #=> true

Very strange. I tried to call :snmp.config() from iex, and it failed because of that, while it works perfectly in erl.

Expected behavior

I would expect that calling :io.get_line to return the same data-type regardless of whether it is being called from Erlang or Elixir. Any Erlang code that uses :io.get_line and is run from Elixir would fail.

I belive it's not about elixir/erlang but about iex/erl. The docs for io:get_line/2 talk a bit about the different data types it may return and conditions for such: https://www.erlang.org/docs/29/apps/stdlib/io.html#get_line/2

Exactly. Any device may return a binary on read, therefore, all Erlang/Elixir code needs to be aware of this possibility and handle it accordingly.

So if I understand correctly, in Elixir we open :standard_io with {:binary, true} while Erlang uses {:binary, false}.

It's then a bug in :snmp.config(). I'll open up a bug in Erlang/OTP :)