Repository navigation
Build char literals directly instead of parsing their text - #447
Merged
Merged
Conversation
Literals in operations, operator assignments and expression refinements were turned into predicates by parsing getValue().toString(). RJ has no char-literal syntax, so '[' or ' ' raised a syntax error, 'a' was read as a variable named a, and '0' as the int 0. Wrap the value as an RJ literal node instead, as StaticConstants already does for resolved constants. Fixes #444 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #444.
Problem
Comparing a
charwith a literal like'[','{',',',' 'or'Z'was rejected withSyntax Error: Invalid refinement expression. Three places (OperationsCheckeroperands, operator assignments, andRefinementTypeChecker#getExpressionRefinements) built a literal's predicate by parsingliteral.getValue().toString(), and RJ has no char-literal token.The literals that "passed" were also wrong, which the issue suspected:
'0'parsed as the int0, not 48'a'parsed as a variablea, so it took the value of any local namedaBoth are unsound. On
main,ErrorCharLiteralComparisonsbelow verifies with no errors.Fix
Predicate.createLit(Object, CtElement)wraps the value with the existingStaticConstants.asLiteralPredicate, the same path resolvedstatic finalconstants already use, so aCharacterbecomes aLiteralChar(an int in Z3). Values it doesn't model fall back to the old parse.Tests
CorrectCharLiteralComparisons: the reproducer from the issue (charAt(i) != '['), punctuation/space/uppercase/escaped comparisons,'0'== 48,'a'with a localain scope, and a+=with a char literalErrorCharLiteralComparisons:'0'is not 0, and'a'is not the locala = 5(both pass silently onmain)./mvnw test: 534 tests, 0 failures.🤖 Generated with Claude Code