Skip to content

Fix compiler crash on invalid nested bitstring#15280

Merged
josevalim merged 3 commits intoelixir-lang:mainfrom
lukaszsamson:ls-compiler-crash-on-bitstring
Apr 16, 2026
Merged

Fix compiler crash on invalid nested bitstring#15280
josevalim merged 3 commits intoelixir-lang:mainfrom
lukaszsamson:ls-compiler-crash-on-bitstring

Conversation

@lukaszsamson
Copy link
Copy Markdown
Contributor

This PR fixes a crash when handling invalid bitstring:

iex(1)> Code.compile_string("""
        defmodule Repro do
          def run do
            <<(<<1>>)::integer>>
          end
        end
        """)
error: conflicting type specification for bit field: "integer" and "bitstring"
└─ nofile:3:14: Repro.run/0

** (CaseClauseError) no case clause matching:

    {:integer, [], nil}

    (elixir 1.20.0-rc.4) src/elixir_bitstring.erl:105: :elixir_bitstring.concat_or_prepend_bitstring/6
    (elixir 1.20.0-rc.4) src/elixir_bitstring.erl:50: :elixir_bitstring.expand/8
    (elixir 1.20.0-rc.4) src/elixir_bitstring.erl:25: :elixir_bitstring.expand/5
    (elixir 1.20.0-rc.4) src/elixir_clauses.erl:195: :elixir_clauses.def/3
    (elixir 1.20.0-rc.4) src/elixir_def.erl:198: :elixir_def."-store_definition/10-lc$^0/1-0-"/3
    (elixir 1.20.0-rc.4) src/elixir_def.erl:199: :elixir_def.store_definition/10
    nofile:2: (module)
    iex:1: (file)

With the changes:

iex(1)> Code.compile_string("""
        defmodule Repro do
          def run do
            <<(<<1>>)::integer>>
          end
        end
        """)
error: conflicting type specification for bit field: "integer" and "bitstring"
└─ nofile:3:14: Repro.run/0

** (CompileError) nofile: cannot compile module Repro (errors have been logged)
    (elixir 1.20.0-rc.4) src/elixir_module.erl:192: anonymous fn/11 in :elixir_module.compile/7
    iex:1: (file)

Comment thread lib/elixir/test/elixir/kernel/binary_test.exs Outdated
Comment thread lib/elixir/test/elixir/kernel/binary_test.exs Outdated
Co-authored-by: José Valim <jose.valim@gmail.com>
Comment thread lib/elixir/test/elixir/kernel/binary_test.exs Outdated
@josevalim josevalim merged commit 5e44c78 into elixir-lang:main Apr 16, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants