Skip to content

Accept the minimum value in signed integer attributes - #142

Open
senzenn wants to merge 2 commits into
codama-idl:mainfrom
senzenn:fix/signed-integer-min
Open

senzenn wants to merge 2 commits into
codama-idl:mainfrom
senzenn:fix/signed-integer-min

Conversation

@senzenn

@senzenn senzenn commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

as_signed_integer parsed the operand of a negation as T and then negated the result, so T::MIN was always rejected. Its magnitude doesn't fit in T. 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 T is reachable.

Tests cover i64::MIN and i8::MIN through the helper, out of range still erroring, and the minimum offset through both pre_offset and post_offset, which read their offset through the same call sites.

One thing worth a look: dropping the now-unnecessary Neg bound means as_signed_integer::<u32>() compiles rather than failing to. Both call sites infer T from a SetOnce<i32> so nothing changes in practice, but say the word if you'd rather keep a bound that pins T to a signed type.

`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.
@senzenn

senzenn commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@lorisleiva

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.

1 participant