parser: retain DECIMAL/NUMERIC scale (was truncated to 0)#52
Merged
Conversation
`type_node->semantic_flags` is uint16_t, but the scale of a DECIMAL(p,s)/NUMERIC(p,s) type was written as `scale << 16` -- shifted entirely out of the 16-bit field and truncated to 0. `DECIMAL(10,2)` recorded precision=10 but scale=0, silently discarding parsed information. Pack both into semantic_flags instead: precision in the low byte, scale in the high byte. A byte each covers all real DECIMAL/NUMERIC types (ANSI max precision 38, scale <= precision); both are clamped to 255 so an out-of-range literal cannot spill into the other field. Tests (tests/test_ddl_statements.cpp): DECIMAL(10,2) retains precision=10/scale=2; NUMERIC(18) retains precision=18/scale=0. Falsifiable: the scale assertion fails under the old `scale << 16`. Full suite 37/37. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyKDAbMWGwiZq4iJx3imsg
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.
Summary
type_node->semantic_flagsisuint16_t, but the scale of aDECIMAL(p,s)/NUMERIC(p,s)type was written asscale << 16— shifted entirely out of the 16-bit field and truncated to 0.DECIMAL(10,2)recorded precision=10 but scale=0, silently discarding parsed information. (No UB — the shift is on auint32_ttemporary — just lost metadata.)Found in the bottom-up parser audit alongside the nested-
CREATE TRIGGERcrash (separate PR). Minor severity: nothing downstream currently reads the packed precision/scale (the analyzer derives the type from the type name and strips the(...)), so this is a "parser must not silently drop what it parsed" correctness fix rather than an observable wrong-result today.Change
Pack both values into
semantic_flags: precision in the low byte, scale in the high byte. A byte each covers all real DECIMAL/NUMERIC types (ANSI max precision 38, and scale ≤ precision); both are clamped to 255 so an out-of-range literal cannot spill into the other field.Decode is
precision = flags & 0xFF,scale = (flags >> 8) & 0xFF.Tests
tests/test_ddl_statements.cpp:DECIMAL(10,2)→ precision=10, scale=2;NUMERIC(18)→ precision=18, scale=0.Falsifiable: the scale assertion fails under the old
scale << 16. Full suite 37/37.