Skip to content

Commit e22f511

Browse files
committed
Fix position of desugared tree wrapped in parentheses
Before this commit, the added testcase produced the following result: scala> while ((( foo ))) {} 1 |while ((( foo ))) {} | ^^^^^^^^^^^ | not found: foo
1 parent 9a0c822 commit e22f511

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,17 @@ object desugar {
10171017
}
10181018

10191019
// begin desugar
1020+
1021+
// Special case for `Parens` desugaring: unlike all the desugarings below,
1022+
// its output is not a new tree but an existing one whose position should
1023+
// be preserved, so we shouldn't call `withPos` on it.
10201024
tree match {
1025+
case Parens(t) =>
1026+
return t
1027+
case _ =>
1028+
}
1029+
1030+
val desugared = tree match {
10211031
case SymbolLit(str) =>
10221032
Apply(
10231033
ref(defn.SymbolClass.companionModule.termRef),
@@ -1096,7 +1106,8 @@ object desugar {
10961106
finalizer)
10971107
}
10981108
}
1099-
}.withPos(tree.pos)
1109+
desugared.withPos(tree.pos)
1110+
}
11001111

11011112
/** Create a class definition with the same info as the refined type given by `parent`
11021113
* and `refinements`.

compiler/test-resources/repl/errmsgs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ scala> { def f: Int = g; val x: Int = 1; def g: Int = 5; }
6464
1 | { def f: Int = g; val x: Int = 1; def g: Int = 5; }
6565
| ^
6666
| `g` is a forward reference extending over the definition of `x`
67+
scala> while ((( foo ))) {}
68+
1 |while ((( foo ))) {}
69+
| ^^^
70+
| not found: foo

0 commit comments

Comments
 (0)