Commit 5d9b68b
committed
Fix Scala parser gaps surfaced by prethink integration testing
ScalaTreeVisitor: mirror the else branch's expression-wrapping fallback
that the then branch already had, so `if (x) a else b` with expression
operands parses (closes asymmetry that threw UnsupportedOperationException).
Add `case j: J => new S.StatementExpression(Tree.randomId(), j)` fallbacks
at ~25 visitUnknown sites where the parser previously crashed on any J
that wasn't exactly an Expression/Statement — covering visitWhileDo
body/cond, visitForDo body/iterable, visitReturn, visitThrow,
visitMatchImpl selector, visitAssign lhs/rhs, visitInfixOp /
visitBinaryOperation / visitInfixMethodCall operands, visitPrefixOp /
visitPostfixOp operand, visitParentheses inner, visitTyped,
visitTypeApply asInstanceOf/isInstanceOf, visitAppliedTypeTree args,
method call target, ArrayAccess array/index, NewArray /
NewArrayWithType elements, NewClassWithArgs constructor args,
annotation args, tuple elements. Try body/finalizer now also accept
Statement, matching the existing ParsedTry behavior.
ScalaParser.sourcePathFromSourceText: was hard-coded to "file.scala"
so every source in a multi-file test collided on the same path and
clobbered each other on print round-trip. Extract package + class
name via a shared derivedRelativePath helper (reusing logic from
parse()) so each source gets a distinct path.
7 new regression tests covering if-else-as-expression (literal/ident
operands), return/throw/assign with if-rhs, binary/tuple/paren with
if-operand, while-with-unit-body, and multi-file distinct paths. Full
rewrite-scala suite passes.1 parent 73aa770 commit 5d9b68b
4 files changed
Lines changed: 248 additions & 48 deletions
File tree
- rewrite-scala/src
- main
- java/org/openrewrite/scala
- scala/org/openrewrite/scala/internal
- test/java/org/openrewrite/scala/tree
Lines changed: 15 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| |||
154 | 152 | | |
155 | 153 | | |
156 | 154 | | |
157 | | - | |
| 155 | + | |
158 | 156 | | |
159 | 157 | | |
160 | 158 | | |
| |||
0 commit comments