<<>> with unit(var) fails to compile


Any idea ? What’s wrong with unit() ?

def serialize(data, s, u \\ 8) do

# mix compile
# (CompileError) lib/[..].ex:L: unit in bitstring expects an integer as argument, got: u

Thanks !

This is a limitation of the BEAM. Nearly every value used in a binary pattern needs to be known statically at compile time.

Some related error-messages do explain that fact, some others don’t. So at least we can say, that the error-message is misleading. And I’m pretty sure, that the value for size must be statically known as well.

Could you please check for size if the message is misleading as well and report them at the issue tracker? Also make sure, that you are checking against latest released version and if possible against master-branch as well.

size() definitely works with a value stated at runtime, it’s just `unit() that doesn’t allow it.

Yup, size() works. I will report on github.

Report what? Is it possible to make unit a variable in erlang?

The misleading error message.