Skip to content

Commit

Permalink
Rethrow SuspendExceptions caught in CodeGen phase (scala#22009)
Browse files Browse the repository at this point in the history
Related PR: scala#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: scala#21983
  • Loading branch information
hamzaremmal authored Nov 26, 2024
2 parents 75ddad2 + 8a5a93a commit c3d6c48
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/backend/jvm/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
registerGeneratedClass(mirrorClassNode, isArtifact = true)
catch
case ex: InterruptedException => throw ex
case ex: CompilationUnit.SuspendException => throw ex
case ex: Throwable =>
ex.printStackTrace()
report.error(s"Error while emitting ${unit.source}\n${ex.getMessage}", NoSourcePosition)
Expand Down
13 changes: 13 additions & 0 deletions tests/pos-macros/i21983/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package example

sealed trait Test

object Test {
case object Foo extends Test

val visitorType = mkVisitorType[Test]

trait Visitor[A] {
type V[a] = visitorType.Out[a]
}
}
3 changes: 3 additions & 0 deletions tests/pos-macros/i21983/UsesTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package example

val _ = Test.Foo
13 changes: 13 additions & 0 deletions tests/pos-macros/i21983/VisitorMacros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package example

import scala.deriving.Mirror
import scala.quoted.*

private def mkVisitorTypeImpl[T: Type](using q: Quotes): Expr[VisitorType[T]] =
'{new VisitorType[T]{}}

transparent inline def mkVisitorType[T]: VisitorType[T] = ${ mkVisitorTypeImpl[T] }

trait VisitorType[T] {
type Out[A]
}

0 comments on commit c3d6c48

Please sign in to comment.