From 8a5a93af0391ceab775a16bd18f6a46d1c5bf88c Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Fri, 22 Nov 2024 13:51:41 +0100 Subject: [PATCH] Rethrow SuspendExceptions in CodeGen phase --- compiler/src/dotty/tools/backend/jvm/CodeGen.scala | 1 + tests/pos-macros/i21983/Test.scala | 13 +++++++++++++ tests/pos-macros/i21983/UsesTest.scala | 3 +++ tests/pos-macros/i21983/VisitorMacros.scala | 13 +++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 tests/pos-macros/i21983/Test.scala create mode 100644 tests/pos-macros/i21983/UsesTest.scala create mode 100644 tests/pos-macros/i21983/VisitorMacros.scala diff --git a/compiler/src/dotty/tools/backend/jvm/CodeGen.scala b/compiler/src/dotty/tools/backend/jvm/CodeGen.scala index c5b0ec0929b8..d4843cd56639 100644 --- a/compiler/src/dotty/tools/backend/jvm/CodeGen.scala +++ b/compiler/src/dotty/tools/backend/jvm/CodeGen.scala @@ -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) diff --git a/tests/pos-macros/i21983/Test.scala b/tests/pos-macros/i21983/Test.scala new file mode 100644 index 000000000000..bf008583c7d9 --- /dev/null +++ b/tests/pos-macros/i21983/Test.scala @@ -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] + } +} diff --git a/tests/pos-macros/i21983/UsesTest.scala b/tests/pos-macros/i21983/UsesTest.scala new file mode 100644 index 000000000000..803e93c328c9 --- /dev/null +++ b/tests/pos-macros/i21983/UsesTest.scala @@ -0,0 +1,3 @@ +package example + +val _ = Test.Foo diff --git a/tests/pos-macros/i21983/VisitorMacros.scala b/tests/pos-macros/i21983/VisitorMacros.scala new file mode 100644 index 000000000000..5a5cc453c525 --- /dev/null +++ b/tests/pos-macros/i21983/VisitorMacros.scala @@ -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] +}