Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation Error with invalid bit pattern #14391

Closed
dmorn opened this issue Apr 3, 2025 · 1 comment
Closed

Compilation Error with invalid bit pattern #14391

dmorn opened this issue Apr 3, 2025 · 1 comment

Comments

@dmorn
Copy link

dmorn commented Apr 3, 2025

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.

josevalim added a commit that referenced this issue Apr 3, 2025
@josevalim
Copy link
Member

Fixed in main and v1.18. Thank you.

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

No branches or pull requests

2 participants