Skip to content

Handle non-binary bitstring in struct default values #14363

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

Merged
merged 2 commits into from
Mar 25, 2025

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Mar 25, 2025

Close #14362

For instance, the erlang AST for <<255, 127::7>> is:

{:bin, 1,
 [
   {:bin_element, 1, {:integer, 1, 255}, :default, [:integer]},
   {:bin_element, 1, {:integer, 1, 127}, {:integer, 1, 7}, [:integer]}
 ]}

To be backported after merge.

defstruct bitstring: <<255, 127::7>>
end

assert struct!(WithBitstring).bitstring == <<255, 127::7>>
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is not needed as even if we use an empty bin in your implementation the value is still the same. Following the issue there should be a check if the module compiles. Optionally there could be an extra test for the new :elixir_erl.elixir_to_erl/2 function clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is not needed as even if we use an empty bin in your implementation the value is still the same.

@Eiji7 good catch thank you! 💜 This was needed by struct_info, fixed.

Following the issue there should be a check if the module compiles.

This is being checked, otherwise defmodule would fail.

Optionally there could be an extra test for the new :elixir_erl.elixir_to_erl/2 function clause.

I thought the same, but I don't think there is any direct test for elixir_to_erl at this moment.

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

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

Beautiful! And 👍 on backport!

@sabiwara sabiwara merged commit a6a38e1 into elixir-lang:main Mar 25, 2025
10 checks passed
@sabiwara sabiwara deleted the bitstring_to_erl branch March 25, 2025 09:07
sabiwara added a commit to sabiwara/elixir that referenced this pull request Mar 25, 2025
@sabiwara
Copy link
Contributor Author

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.

Can not set the bitstring value in a struct definition
3 participants