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

Pattern match with <> operator doesn't recognize that bound variable has size #3837

Closed
MSch opened this issue Oct 5, 2015 · 1 comment
Closed

Comments

@MSch
Copy link
Contributor

MSch commented Oct 5, 2015

Since <> concatenates two binaries, I would have expected this to work, just like "fixed_pattern" <> rest = whatever works, but it doesn't.

root = "/home/msch/code"
path = "/home/msch/code/project/some/file.ex"
(^root <> rest) = path
** (CompileError) iex:7: a binary field without size is only allowed at the end of a binary pattern

I've got to do this:

root = "/home/msch/code"
path = "/home/msch/code/project/some/file.ex"
root_size = byte_size(root)
<<^root::binary-size(root_size), rest::binary>> = path

Is this a bug or an inherent limitation?

@josevalim
Copy link
Member

We can only fix this if we fix it directly in Erlang because we could not precalculate the size in function clauses where the same issue could happen.

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

No branches or pull requests

2 participants