Compile Error does not indicate line-of-error in source file

Tags: #<Tag:0x00007f1148c3a658> #<Tag:0x00007f1148c3a3b0>



I get a Compile Error which omits the line of code in my source file that is causing the error.

Any help please.

iex(14)> defmodule Test do
...(14)>   def match(<<_::size(pos)-bytes, code::8, _::bytes>>, pos) do
...(14)>     code
...(14)>   end
...(14)> end
** (CaseClauseError) no case clause matching: []
    (elixir) src/elixir_bitstring.erl:113: :elixir_bitstring.expand_each_spec/4
    (elixir) src/elixir_bitstring.erl:86: :elixir_bitstring.expand_specs/5
    (elixir) src/elixir_bitstring.erl:29: :elixir_bitstring.expand/6
    (elixir) src/elixir_bitstring.erl:9: :elixir_bitstring.expand/4

pos needs to be before <<_::size(pos)-bytes, ...>>> in the argument list to the function.


Thanks so much… but why didn’t the compiler point out the line?


I don’t know, maybe someone from the core team can tell us. Or maybe you can open an issue on github?


@idiot I have. Thanks again for pointing it out.


Actually, my suggestion doesn’t work either

iex(14)> defmodule Test do
...(14)>   def match(pos, <<_::size(pos)-bytes, code::8, _::bytes>>) do
...(14)>     code
...(14)>   end
...(14)> end
** (CompileError) iex:15: variable pos@1 is unbound
    (stdlib) lists.erl:1338: :lists.foreach/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (iex) lib/iex/evaluator.ex:219: IEx.Evaluator.handle_eval/5

So it might be something like this

defmodule Test do
  def match(stream, pos) do
    <<_::size(pos)-bytes, code::8, _::bytes>> = stream


just noticed that, but at least the compiler barks it out, it is easier to trace


I think I’ve confused it with something like this

defp decode(<<@string::8, len::16, str::size(len)-bytes, rest::bytes>>, acc) do
  decode(rest, [str | acc])

where it’s possible to use size with values matched inside the binary.