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

Bitstring syntax returns inconsistent result when using erlang:byte_size as binary size #8280

Closed
sabiwara opened this issue Mar 20, 2024 · 1 comment · Fixed by #8284
Closed
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@sabiwara
Copy link
Contributor

sabiwara commented Mar 20, 2024

Describe the bug
When using :(erlang:byte_size(SomeVar))/binary in a bit string match, the match fails when it shouldn't.

To Reproduce

Within a module:

-module(foo).
-export([foo/0]).

foo() ->
  A = 0,
  B = <<1, 2, 3>>,
  % works
  <<A, B:3/binary>> = <<0, 1, 2, 3>>,
  % fails
  <<A, B:(erlang:byte_size(B))/binary>> = <<0, 1, 2, 3>>.
** exception error: no match of right hand side value <<0,1,2,3>>
     in function  foo:foo/0 (foo.erl, line 10)

Note: interpreted code in erl is unaffected, only happens within compiled modules.

Expected behavior
The pattern should match.

Affected versions
Reproduced on both:

  • 26.2.1
  • 27.0-rc1

OS: macOS 14.1.1

Additional context

Originally reported in elixir-lang/elixir#13420.

@sabiwara sabiwara added the bug Issue is reported as a bug label Mar 20, 2024
@bjorng bjorng self-assigned this Mar 20, 2024
@bjorng bjorng added the team:VM Assigned to OTP team VM label Mar 20, 2024
bjorng added a commit to bjorng/otp that referenced this issue Mar 20, 2024
@bjorng bjorng linked a pull request Mar 20, 2024 that will close this issue
@bjorng
Copy link
Contributor

bjorng commented Mar 20, 2024

Thanks! Fixed in the linked pull request.

bjorng added a commit that referenced this issue Mar 22, 2024
@bjorng bjorng closed this as completed in d0dc1eb Mar 22, 2024
rickard-green pushed a commit that referenced this issue Apr 12, 2024
…int-26

* bjorn/compiler/fix-bs_ensure/GH-8280/OTP-19035:
  Fix failing binary match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants