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

Bit syntax integer signedness #283

Merged
merged 9 commits into from
Feb 27, 2020

Conversation

FrankBro
Copy link
Collaborator

@FrankBro FrankBro commented Feb 26, 2020

According to https://erlang.org/doc/programming_examples/bit_syntax.html#defaults

The default signedness for integer is unsigned. Feed on the specifiers to control signedness and make the default unsigned, which leads to unspecified signedness going from integer() to non_neg_integer().

@FrankBro
Copy link
Collaborator Author

FrankBro commented Feb 26, 2020

Actually I think there's still a problem.

-spec receiver(binary()) -> non_neg_integer().
receiver(B) ->
    <<I>> = B,
    I.

-spec emitter(integer()) -> binary().
emitter(I) ->
    B = <<I>>,
    B.

I think for receiver, it makes sense to require non_neg_integer() but with these changes, emitter errors out because we're building the binary with an integer() instead of a non_neg_integer().

Considering the following:

1> <<A/unsigned>> = <<-1>>.
<<"ÿ">>
2> A.
255
3> <<B/signed>> = <<-1>>.
<<"ÿ">>
4> B.
-1

I think it should allow any sort of integer if it's on RHS, right?

@Zalastax
Copy link
Collaborator

From linked article:

The signedness specification can be either signed or unsigned. Notice that signedness only matters for matching.

@codecov-io
Copy link

codecov-io commented Feb 26, 2020

Codecov Report

Merging #283 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #283      +/-   ##
==========================================
+ Coverage   87.68%   87.71%   +0.02%     
==========================================
  Files          18       18              
  Lines        2656     2661       +5     
==========================================
+ Hits         2329     2334       +5     
  Misses        327      327
Impacted Files Coverage Δ
src/typechecker.erl 90.98% <100%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd02b45...387c966. Read the comment docs.

@FrankBro
Copy link
Collaborator Author

From linked article:

The signedness specification can be either signed or unsigned. Notice that signedness only matters for matching.

Indeed. Fixed with the new commit.

@Zalastax
Copy link
Collaborator

Great! Add your examples as test too 😃

@FrankBro
Copy link
Collaborator Author

Should be good now. Requests approvals and I think this is ready to merge.

Copy link
Collaborator

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Very good! I just have a few style comments. Hope you agree.

@FrankBro
Copy link
Collaborator Author

I agreed with all of them :)

@zuiderkwast
Copy link
Collaborator

Awesome! Then I have just one more but just it's a comment about a comment...

@FrankBro
Copy link
Collaborator Author

Should I merge?

Copy link
Collaborator

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Great! I will squash and merge.

@zuiderkwast
Copy link
Collaborator

Or better you merge yourself, you can squash as you want. 👍

@FrankBro FrankBro merged commit f4e95cb into josefs:master Feb 27, 2020
berbiche pushed a commit to berbiche/Gradualizer that referenced this pull request Feb 9, 2021
Respect default unsignedness for integer bit-string matching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants