Support module attributes inside << ... >>

38 views
Skip to first unread message

Mário Guimarães

unread,
Apr 21, 2020, 6:28:59 AM4/21/20
to elixir-lang-core
Hello,

It would be very useful if module attributes could be used when defining binary values via << ... >>, like in this example

defmodule MyModule do
 
@param 8
 
@bin << 0 :: @param >>
end

which fails to compile

== Compilation error in file lib/..../file.ex ==
** (CompileError) lib/..../file.ex:6: unknown bitstring specifier: Module.__get_attribute__(__MODULE__, :param, 6)
   
(elixir) src/elixir_bitstring.erl:171: :elixir_bitstring.expand_specs/6
   
(elixir) src/elixir_bitstring.erl:41: :elixir_bitstring.expand/8
   
(elixir) src/elixir_bitstring.erl:20: :elixir_bitstring.expand/4
   
(stdlib) lists.erl:1354: :lists.mapfoldl/3
   
(stdlib) lists.erl:1355: :lists.mapfoldl/3
   
(elixir) expanding macro: Kernel.@/1

Thanks
Mário Guimarães

Mário Guimarães

unread,
Apr 21, 2020, 6:40:13 AM4/21/20
to elixir-lang-core
I discovered that it is possible to achieve the same effect this way

defmodule MyModule do
 
@param 8

  param
= @param
 
@bin << 0 :: size(param) >>
end

so perhaps this is enough.

Thanks
Reply all
Reply to author
Forward
0 new messages