Skip to content

Support calculations in size specifier for binaries #6273

@michalmuskala

Description

@michalmuskala

In Erlang, it's possible to create a function like this:

test(X) ->
    << 0:(X * 8) >>.

This is not possible to express in Elixir currently except for setting up a separate variable to do the size computation.

We can't support this directly as:

<<0 :: x * 8>>

since that would be ambiguous with the:

<<0 :: size * unit>>

notation. Fortunately we can support such calculations inside the size specifier:

<<0 :: size(x * 8)>>

Thanks to fowlduck for reporting this initially on IRC.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions