Skip to content

Compilation Error with invalid bit pattern #14391

@dmorn

Description

@dmorn

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.2.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Elixir 1.18.3 (compiled with Erlang/OTP 27)

Operating system

MacOS 15.3.2 (24D81)

Current behavior

Compiler's output

Compiling 5 files (.ex)
    warning: variable "rest" is unused (if the variable is not meant to be used, prefix it with an underscore)
    │
 43 │          @start_code_4b <> <<0::1, prio::2, type::5, rest::bitstring>>,
    │                                                      ~~~~
    │
    └─ lib/vt/sub_proxy/nalu/parser.ex:43:54: VT.SubProxy.NALU.Parser.split_nalu/3


== Compilation error in file lib/vt/sub_proxy/nalu/parser.ex ==
** (RuntimeError) found error while checking types for VT.SubProxy.NALU.Parser.handle_buffer/4:

** (RuntimeError) found error while checking types for VT.SubProxy.NALU.Parser.parse_and_forward/1:

** (RuntimeError) found error while checking types for VT.SubProxy.NALU.Parser.split_nalu/3:

** (MatchError) no match of right hand side value: nil
The exception happened while checking this code:

defp split_nalu(
       <<"\0\0\0\x01"::binary,
         <<0::integer-size(1), prio::integer-size(2), type::integer-size(5), rest::bitstring>>::binary>>,
       _next,
       _acc
     ) do
  IO.inspect(type, label: "TYPE")
  IO.inspect(prio, label: "PRIO")
  :erlang.error(RuntimeError.exception([]), :none, error_info: %{module: Exception})
end

Please report this bug at: https://github.com/elixir-lang/elixir/issues

The exception happened while checking this code:

defp parse_and_forward(state = %{buffer: payload, next: next}) do
  _ = split_nalu(payload, next, [])
  {[], state}
end

Please report this bug at: https://github.com/elixir-lang/elixir/issues

The exception happened while checking this code:

def handle_buffer(:input, buffer, _ctx, state) do
  parse_and_forward(
    Kernel.update_in(state, [:buffer], fn x -> <<x::binary, buffer.payload::binary>> end)
  )
end

Please report this bug at: https://github.com/elixir-lang/elixir/issues

    (elixir 1.18.3) lib/module/types/pattern.ex:495: Module.Types.Pattern.of_pattern/4
    (elixir 1.18.3) lib/module/types/pattern.ex:57: Module.Types.Pattern.of_pattern_args_index/5
    (elixir 1.18.3) lib/module/types/pattern.ex:46: Module.Types.Pattern.of_pattern_args/5
    (elixir 1.18.3) lib/module/types/pattern.ex:35: Module.Types.Pattern.of_head/7
    (elixir 1.18.3) lib/module/types.ex:242: anonymous fn/6 in Module.Types.local_handler/7
    (elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir 1.18.3) lib/module/types.ex:236: Module.Types.local_handler/7
    (elixir 1.18.3) lib/module/types.ex:218: Module.Types.local_handler/5

For reference, the compilation error appears from 1.18.0-opt27. On 1.17.3-otp27 we get:

Compiling 5 files (.ex)
    warning: variable "rest" is unused (if the variable is not meant to be used, prefix it with an underscore)
    │
 43 │          @start_code_4b <> <<0::1, prio::2, type::5, rest::bitstring>>,
    │                                                      ~~~~
    │
    └─ lib/vt/sub_proxy/nalu/parser.ex:43:54: VT.SubProxy.NALU.Parser.split_nalu/3


== Compilation error in file lib/vt/sub_proxy/nalu/parser.ex ==
** (CompileError) Elixir.VT.SubProxy.NALU.Parser: expecting pattern in split_nalu/3
    (stdlib 6.2) lists.erl:2310: :lists.foreach_1/2

Expected behavior

It is a compiler error, I expect it to either report that the code cannot be compiled and why. I know the code is invalid, the bit-pattern should be written as <<0, 0, 0, 1, 0::1, prio::2, type::5, rest::bitstring>> instead of what I'm doing there, but anyway I think it's worth reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions