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

fixes #589 allow min and max to be within range #733

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davetayls
Copy link

fixes #589

Allow min and max to be within range of the specified format

@davetayls
Copy link
Author

Hey @ahl does this fix look ok to you?

Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

Thanks for working on this; I don't think this is quite right. Please see my notes.

Comment on lines +1020 to +1021
&& (min.map(|f| f.ge(imin)).unwrap_or(false))
&& (max.map(|f| f.le(imax)).unwrap_or(false))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't seem quite right. Previously the logic said: "if it's None OR is the specified bound". Now this says "if it's Some AND is within the specified bound". So this will only apply if both the minimum and maximum values are set in the schema.

I'm not sure of the best path forward here. I tried adjusting this, but then the NonZeroUXX tests failed. One option might be to specify add formats for the NonZeroXX types in the table above and then here to filter rather than find.

@@ -2115,6 +2116,35 @@ mod tests {
validate_builtin!(std::collections::BTreeSet<u32>);
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest deleting this test and adding some types to typify/tests/schemas/simple-types.json. These are typically easier to create, easier to update, and easier to understand.

@@ -1011,14 +1011,14 @@ impl TypeSpace {
];

if let Some(format) = format {
if let Some((_, ty, imin, imax)) = formats
if let Some((_fmt, ty, imin, imax)) = formats
.iter()
.find(|(int_format, _, _, _)| int_format == format)
{
// If the type matches with other constraints, we're done.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment no longer seems to accurately describe the code below it.

@davetayls
Copy link
Author

Thanks, I will take a look through them

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.

Adding a "maximum" limit to an integer changes the inner Rust type
2 participants