Skip to content

Commit c5fb061

Browse files
committed
Fix #5997: Add missing parentheses
1 parent 1636a25 commit c5fb061

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

compiler/test/dotc/pos-recompilation.whitelist

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ i4819
300300
i4984
301301
i4999
302302
i5090
303+
i5997
303304
i518
304305
i5188
305306
i523

library/src/scala/tasty/reflect/Printers.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ trait Printers
758758
printType(tree.tpe)
759759

760760
case Term.Select(qual, name) =>
761-
printTree(qual)
761+
printQualTree(qual)
762762
if (name != "<init>" && name != "package")
763763
this += "." += name
764764
this
@@ -941,6 +941,14 @@ trait Printers
941941

942942
}
943943

944+
def printQualTree(tree: Tree): Buffer = tree match {
945+
case Term.IsIf(_) | Term.IsMatch(_) | Term.IsWhile(_) | Term.IsTry(_) | Term.IsReturn(_) =>
946+
this += "("
947+
printTree(tree)
948+
this += ")"
949+
case _ => printTree(tree)
950+
}
951+
944952
def flatBlock(stats: List[Statement], expr: Term): (List[Statement], Term) = {
945953
val flatStats = List.newBuilder[Statement]
946954
def extractFlatStats(stat: Statement): Unit = stat match {

tests/pos/i5997.decompiled

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Test() {
2+
val v1: scala.Option[scala.Int] = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1)))
3+
val v2: scala.Option[scala.Int] = (try scala.Some.apply[scala.Int](1) finally ()).map[scala.Int](((v: scala.Int) => v.+(1)))
4+
val v3: scala.Option[scala.Int] = (1 match {
5+
case _ =>
6+
scala.Some.apply[scala.Int](1)
7+
}).map[scala.Int](((v: scala.Int) => v.+(1)))
8+
val v4: java.lang.String = (while (true) ()).toString()
9+
def v5: scala.Option[scala.Predef.String] = scala.Some.apply[java.lang.String]((return scala.Some.apply[java.lang.String]("a")).toString())
10+
}

tests/pos/i5997.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Test {
2+
val v1 = (if true then Some(1) else None).map(v => v+1)
3+
val v2 = (try Some(1) finally {}).map(v => v+1)
4+
val v3 = (1 match { case _ => Some(1) }).map(v => v+1)
5+
val v4 = (while (true) ()).toString
6+
def v5: Option[String] = Some((return Some("a")).toString)
7+
}

tests/run-with-compiler/i5997.check

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1)))

tests/run-with-compiler/i5997.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
import quoted.Toolbox.Default._
4+
val v = '{ (if true then Some(1) else None).map(v => v+1) }
5+
println(v.show)
6+
}
7+
}

0 commit comments

Comments
 (0)