Skip to content

Commit bade85e

Browse files
authored
Merge pull request #2059 from dotty-staging/fix/inline-EmptyTree
Fix #2056: Backend crash when inlined method contains try
2 parents c90ea6b + 094cd9f commit bade85e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,11 @@ object Trees {
712712
override def toList: List[Tree[T]] = flatten(trees)
713713
override def toString = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
714714
override def withPos(pos: Position): this.type = {
715-
val newTrees = trees.map(_.withPos(pos))
716-
new Thicket[T](newTrees).asInstanceOf[this.type]
715+
val newTrees = trees.mapConserve(_.withPos(pos))
716+
if (trees eq newTrees)
717+
this
718+
else
719+
new Thicket[T](newTrees).asInstanceOf[this.type]
717720
}
718721
override def pos = (NoPosition /: trees) ((pos, t) => pos union t.pos)
719722
override def foreachInThicket(op: Tree[T] => Unit): Unit =

tests/pos/i2056.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object Test {
2+
inline def crash() = {
3+
try {
4+
println("hi")
5+
} catch {
6+
case e: Exception =>
7+
}
8+
}
9+
10+
def main(args: Array[String]): Unit = {
11+
crash()
12+
}
13+
}

0 commit comments

Comments
 (0)