Skip to content

Commit c3d6c48

Browse files
authored
Rethrow SuspendExceptions caught in CodeGen phase (#22009)
Related PR: #21651 There, a mechanism was added to the Phase classes, where any phase could catch a SuspendException and have a compilation unit suspended (stopped and recompiled later). In this fix, we rethrow incorrectly caught SuspendExceptions, so that the aforementioned mechanism can take care of the rest. Fixes: #21983
2 parents 75ddad2 + 8a5a93a commit c3d6c48

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

compiler/src/dotty/tools/backend/jvm/CodeGen.scala

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
8484
registerGeneratedClass(mirrorClassNode, isArtifact = true)
8585
catch
8686
case ex: InterruptedException => throw ex
87+
case ex: CompilationUnit.SuspendException => throw ex
8788
case ex: Throwable =>
8889
ex.printStackTrace()
8990
report.error(s"Error while emitting ${unit.source}\n${ex.getMessage}", NoSourcePosition)

tests/pos-macros/i21983/Test.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example
2+
3+
sealed trait Test
4+
5+
object Test {
6+
case object Foo extends Test
7+
8+
val visitorType = mkVisitorType[Test]
9+
10+
trait Visitor[A] {
11+
type V[a] = visitorType.Out[a]
12+
}
13+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package example
2+
3+
val _ = Test.Foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example
2+
3+
import scala.deriving.Mirror
4+
import scala.quoted.*
5+
6+
private def mkVisitorTypeImpl[T: Type](using q: Quotes): Expr[VisitorType[T]] =
7+
'{new VisitorType[T]{}}
8+
9+
transparent inline def mkVisitorType[T]: VisitorType[T] = ${ mkVisitorTypeImpl[T] }
10+
11+
trait VisitorType[T] {
12+
type Out[A]
13+
}

0 commit comments

Comments
 (0)