Skip to content

Invalid code emitted after type info pass #10562

@josevalim

Description

@josevalim

Describe the bug

Take this code:

-module(clean_minimal).
-export([test/0]).

%% This triggers the bug
buggy(X) ->
    _ = id(X),
    case X =:= <<"a">> orelse X =:= <<"b">> of
        false -> outside;
        true ->
            Y = case X of <<"a">> -> 1; _ -> 2 end,
            {inside, Y}
    end.

id(Z) -> Z.

test() ->
    io:format("buggy(<<\"c\">>) = ~p~n", [buggy(<<"c">>)]).

Now compile and execute it:

$ erlc clean_minimal.erl && erl -noshell -eval "clean_minimal:test(), init:stop()" && erlc +no_type_opt clean_minimal.erl && erl -noshell -eval "io:format(\"~nWith +no_type_opt:~n\"), clean_minimal:test(), init:stop()"

It emits:

buggy(<<"c">>) = {inside,2}

With +no_type_opt:
buggy(<<"c">>) = outside

Showing the type optimisation makes it enter the wrong branch.

Affected versions

Checked only on Erlang/OTP 28 [erts-16.2]

Additional context

Originally reported here: elixir-lang/elixir#15069

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions