otp icon indicating copy to clipboard operation
otp copied to clipboard

Compiler changes the semantics of the program causing crashes

Open josevalim opened this issue 1 month ago • 1 comments

Describe the bug

Compile this code:

-module(foo).
-export([f/1]).

f(X) ->
  lists:append(lists:map(fun(Y) -> Y end, [1, 2]), [X * X + X * X]).

And run it with:

$ erlc foo.erl && erl -eval "foo:f(2)."
Erlang/OTP 28 [erts-16.1.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Error! Failed to eval: foo:f(2).

Runtime terminating during boot ({badarith,[{erlang,'+',[4,[]],[{error_info,#{module=>erl_erts_errors}}]},{foo,f,1,[{file,"foo.erl"},{line,5}]},{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,920}]},{init,start_it,1,[]},{init,start_em,1,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...done

Expected behavior

It should return [1, 2, 8] instead.

Affected versions

A user has reported this issue on OTP 27 and OTP 28. See here: https://github.com/elixir-lang/elixir/issues/15003.

josevalim avatar Dec 08 '25 18:12 josevalim

Thanks for your report, I've fixed it in https://github.com/erlang/otp/pull/10456

jhogberg avatar Dec 09 '25 09:12 jhogberg