Commit 305085c
authored
Fix GroovyParserVisitor cast dispatch for parenthesized expressions (#7470)
`visitCastExpression` distinguished Java-style `(Type) expr` from
Groovy `as`-style `expr as Type` by peeking at `source.charAt(cursor)`:
if the next character was `(`, assume Java-style. For an expression
like `(foo as Bar).name as Set`, the outer `as`-style cast's expression
itself starts with `(`, so the parser took the Java-style branch,
mis-parsed the cast as a C-style cast, and produced an LST that failed
print idempotency. Downstream, this can cascade into later parse
failures (observed as `Failed to parse ... at cursor position N` on
unrelated single-quoted strings far past the actual offending cast).
Use `CastExpression#isCoerce()` — the Groovy AST's authoritative flag
for `as`-style coercion — instead of peeking at the source.1 parent ace0569 commit 305085c
2 files changed
Lines changed: 15 additions & 2 deletions
File tree
- rewrite-groovy/src
- main/java/org/openrewrite/groovy
- test/java/org/openrewrite/groovy/tree
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1482 | 1482 | | |
1483 | 1483 | | |
1484 | 1484 | | |
1485 | | - | |
1486 | | - | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
1487 | 1489 | | |
1488 | 1490 | | |
1489 | 1491 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
126 | 137 | | |
0 commit comments