Conversation
`as_signed_integer` parsed the operand of a negation as `T` and then
negated the result, so `T::MIN` was always rejected: its magnitude does
not fit in `T`. Every attribute reading a signed integer was affected,
including `#[codama(default_value = -9223372036854775808)]` ("unrecognized
value") and `#[codama(pre_offset(offset = -2147483648))]` ("expected a
signed integer").
Parse the sign together with the digits so the whole range of `T` is
reachable. This also drops the `Neg` bound, which is no longer needed.
post_offset reads its offset through the same as_signed_integer call sites as pre_offset, so pin the minimum value there too. Move the pre_offset case to the keyword form the bug report used, and split the packed expr test so each case follows the shape of its neighbours.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
as_signed_integerparsed the operand of a negation asTand then negated the result, soT::MINwas always rejected. Its magnitude doesn't fit inT. Every attribute reading a signed integer hit this:#[codama(default_value = -9223372036854775808)]gives "unrecognized value"#[codama(pre_offset(offset = -2147483648))]gives "expected a signed integer"Now the sign is parsed together with the digits, so the whole range of
Tis reachable.Tests cover
i64::MINandi8::MINthrough the helper, out of range still erroring, and the minimum offset through bothpre_offsetandpost_offset, which read their offset through the same call sites.One thing worth a look: dropping the now-unnecessary
Negbound meansas_signed_integer::<u32>()compiles rather than failing to. Both call sites inferTfrom aSetOnce<i32>so nothing changes in practice, but say the word if you'd rather keep a bound that pinsTto a signed type.