Skip to content

Fix bin comprehensions when option is used - #15473

Merged
sabiwara merged 4 commits into
elixir-lang:mainfrom
sabiwara:bin-comprehension
Jun 15, 2026
Merged

Fix bin comprehensions when option is used#15473
sabiwara merged 4 commits into
elixir-lang:mainfrom
sabiwara:bin-comprehension

Conversation

@sabiwara

@sabiwara sabiwara commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Fix #15460

Addresses both the regression on integer and the original inconsistency issue for variables/operations.

iex> k = 8;  bin = <<0, 1, 9, 2, 0, 3>>
iex> for(<<0::8, x::8 <- bin>>, uniq: true, do: x)
[1, 3]
iex> for(<<0::8, x::size(^k * 1) <- bin>>, uniq: true, do: x)
[1, 3]
iex> for(<<0::8, x::size(^k) <- bin>>, uniq: true, do: x)
[1, 3]

I don't know if there is a better way to avoid having to drill down the variables.
This is the only way I found to distinguish between a variable that is available from before the comprehension or a var from the generators.

@sabiwara
sabiwara force-pushed the bin-comprehension branch from 267e48c to a3eecec Compare June 15, 2026 01:45
@sabiwara sabiwara changed the title [WIP] Fix bin comprehensions when option is used Fix bin comprehensions when option is used Jun 15, 2026
@sabiwara
sabiwara force-pushed the bin-comprehension branch from a3eecec to 3ff2ece Compare June 15, 2026 02:40
@sabiwara

Copy link
Copy Markdown
Contributor Author

OK, I think this is now ready to ship.

@sabiwara
sabiwara force-pushed the bin-comprehension branch from 3ff2ece to a39e91a Compare June 15, 2026 07:39
@sabiwara
sabiwara force-pushed the bin-comprehension branch from a39e91a to 02612d3 Compare June 15, 2026 07:39

@josevalim josevalim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd perhaps add a test for nested generators and we are good to go!!! Awesome job and please backport!!

@sabiwara

Copy link
Copy Markdown
Contributor Author

@josevalim is it what you had in mind by nested generators? dd490a9

@josevalim

Copy link
Copy Markdown
Member

Yes!!!!

@sabiwara
sabiwara merged commit 2421be6 into elixir-lang:main Jun 15, 2026
15 checks passed
@sabiwara
sabiwara deleted the bin-comprehension branch June 15, 2026 08:32
sabiwara added a commit that referenced this pull request Jun 15, 2026
* Fix bin comprehensions - static size

* Fix bin comprehensions - pinned var size

* Fix bin comprehensions - operations

* Add tests for nested generators
@sabiwara

Copy link
Copy Markdown
Contributor Author

Backported ✅

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Preexisting bug and 1.20 regression in bitstring for generator with reduce/unique

2 participants