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

Direct ranges in fields e.g. foo: 0..255 #174

Merged
merged 4 commits into from
Apr 19, 2023
Merged

Conversation

rooooooooob
Copy link
Collaborator

@rooooooooob rooooooooob commented Apr 14, 2023

Previously they were only supported at the top-level. Incorrect parsing lead these to be treated as a constant of the lower bound.

Fixes #172

better coverage between top-level vs signed_ints member for various
ranges that map to primitives

fix for when >isize::MAX limits are used as we used isize when i128
would be better for covering all possibilities (i64, u64, f64)

float ranges now panic when they have a decimal part as we were silently
ignoring this. Issue created: #178

Previously they were only supported at the top-level.
Incorrect parsing lead these to be treated as a constant of the lower
bound.

Fixes #172
u_64: uint .size 8,
i_8: int .size 1,
i_8: -128..127,
Copy link
Contributor

Choose a reason for hiding this comment

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

could we keep the old test along with the new one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gostkin is this good enough coverage now? to get 100% we'd have to have more structs to test .le, .size and n..m for all cases but this should at least improve it, and is more coverage than we previously had before this PR. The code mostly follows the same path so I don't think we'd gain much from that either.

better coverage between top-level vs signed_ints member for various
ranges that map to primitives

fix for when >isize::MAX limits are used as we used `isize` when `i128`
would be better for covering all possibilities (`i64`, `u64`, `f64`)

float ranges now panic when they have a decimal part as we were silently
ignoring this. Issue created: #178
@@ -176,11 +176,19 @@ fn parse_type_choices(
}
}

fn type2_to_number_literal(type2: &Type2) -> isize {
fn type2_to_number_literal(type2: &Type2) -> i128 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change was to fix an issue noticed when I tried to add u64::MAX as a bound to something and it was rolling over to -1 silently.

Type2::UintValue { value, .. } => *value as i128,
Type2::IntValue { value, .. } => *value as i128,
Type2::FloatValue { value, .. } => {
// FloatToInt trait still experimental so just directly check
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm guessing this was more of something copy-pasted that went unnoticed during the float PR that someone made. I don't think we'd want silent converting to integers as the preferred behavior there.

@gostkin gostkin merged commit 03fdcf5 into master Apr 19, 2023
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.

Integer ranges seem broken, treated as single constant
3 participants