Skip to content

fix: read PostgreSQL 16's 0x/0o/0b integers and digit separators - #184

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/integer-literal-grammar
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/integer-literal-grammar

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #127

Problem

Integer bounds and elements threw FormatException on text PostgreSQL 16 and later reads. Examples: Int32Range.Parse("[0x1F,)") and Int32Set.Parse("{1_000,0o17,0b101}"). This hit Int32Range, Int64Range, their multiranges, Int16Set, Int32Set, Int64Set and the wrapper sets.

Change

  • New src/CodoMetis.ValueRanges/Internals/IntegerLiteral.cs holds PostgreSQL 16's int2/int4/int8 grammar, measured on 16 and 18, which agree:

    • an optional sign, then decimal digits, or 0x/0o/0b in either case followed by digits in that base;
    • one _ between digits, or directly after the prefix (0x_1F);
    • the magnitude is checked before the sign is applied, so -0x80000000 is int.MinValue;
    • past the type it throws OverflowException, as int.Parse did.

    It rejects 0x, 0x1__F, 0x1F_, _1, 1_, 00x1, 0x-1, 0o8, 0x 1F and 1e3, as PostgreSQL does. Like DecimalLiteral, it ignores the provider. Decimal text without separators still takes the BCL fast path.

  • All five integer ParseValue methods go through it. The multiranges, the wrapper arities, JSON, the TypeConverter and the EF bridge all reach it through those methods.

  • Docs: one paragraph in docs/serialization.md#parse-a-literal, claim J39. The CHANGELOG entry is under 10.0.0 → Fixed.

Tests

Note: the JSON writer for an integer wrapper still checks the element's own text with long.TryParse. A wrapper that formats itself as 0x1F is rejected there, while the literal and the EF bridge now read it as 31. Both sides fail loudly or agree on the value, so I left it as is.

🤖 Generated with Claude Code

Integer bounds and elements threw on text PostgreSQL 16 and 18 read: `[0x1F,)` and
`{1_000,0o17,0b101}`. Every integer ParseValue (Int32Range, Int64Range, Int16Set, Int32Set,
Int64Set, and through them the multiranges and wrapper arities) now goes through IntegerLiteral,
measured on PostgreSQL 16 and 18: a prefix in either case, one underscore after it or between
digits, the magnitude checked before the sign so the minimum is reachable in every base, and an
OverflowException past the type as before. `0x`, `0x1__F`, `0x1F_`, `_1`, `00x1` and `0o8` still
throw, and the provider never reaches the grammar.

IntegerLiteralGrammarTests holds the measured table for int2/int4/int8 (36 of 61 rows fail with the
fix reverted; the other 25 are refusals). LiteralCorpusProbeTests gains the edge cases; its 20 #127
candidates are removed as fixed, and the hex spelling of (,max] joins the #132 candidates.

Closes #127

Found-By: OT
Defect-Class: LIT

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 34e1990 into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/integer-literal-grammar branch October 18, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/literals Parse, TryParse and formatting bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference

Projects

None yet

1 participant