Skip to content

Commit bf9f055

Browse files
authored
Merge pull request #3527 from dotty-staging/fix-parens-desugar
Fix position of desugared tree wrapped in parentheses
2 parents 1d79ae2 + 7bce28e commit bf9f055

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
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),
@@ -1057,8 +1067,6 @@ object desugar {
10571067
}
10581068
case PrefixOp(op, t) =>
10591069
Select(t, nme.UNARY_PREFIX ++ op.name)
1060-
case Parens(t) =>
1061-
t
10621070
case Tuple(ts) =>
10631071
val arity = ts.length
10641072
def tupleTypeRef = defn.TupleType(arity)
@@ -1096,7 +1104,8 @@ object desugar {
10961104
finalizer)
10971105
}
10981106
}
1099-
}.withPos(tree.pos)
1107+
desugared.withPos(tree.pos)
1108+
}
11001109

11011110
/** Create a class definition with the same info as the refined type given by `parent`
11021111
* 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)