From cc698957a9f5004bd7328989fb68305e001a87e8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 14 Feb 2024 10:10:34 +0100 Subject: [PATCH 1/2] Improve -Xprint-suspension message --- compiler/src/dotty/tools/dotc/Run.scala | 2 +- tests/neg-macros/annot-suspend-cycle.check | 2 +- tests/neg-macros/macros-in-same-project-4.check | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 4e0b7d09e95f..d18a2ddc7db0 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -141,7 +141,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint |""" val enableXprintSuspensionHint = if ctx.settings.XprintSuspension.value then "" - else "\n\nCompiling with -Xprint-suspension gives more information." + else "\n\nCompile with -Xprint-suspension for information." report.error(em"""Cyclic macro dependencies $where |Compilation stopped since no further progress can be made. | diff --git a/tests/neg-macros/annot-suspend-cycle.check b/tests/neg-macros/annot-suspend-cycle.check index e3ecea7345fd..437398f1d668 100644 --- a/tests/neg-macros/annot-suspend-cycle.check +++ b/tests/neg-macros/annot-suspend-cycle.check @@ -9,4 +9,4 @@ Compilation stopped since no further progress can be made. To fix this, place macros in one set of files and their callers in another. -Compiling with -Xprint-suspension gives more information. +Compile with -Xprint-suspension for information. diff --git a/tests/neg-macros/macros-in-same-project-4.check b/tests/neg-macros/macros-in-same-project-4.check index 79c78fd0fb7f..f027f57637f4 100644 --- a/tests/neg-macros/macros-in-same-project-4.check +++ b/tests/neg-macros/macros-in-same-project-4.check @@ -3,4 +3,4 @@ Compilation stopped since no further progress can be made. To fix this, place macros in one set of files and their callers in another. -Compiling with -Xprint-suspension gives more information. +Compile with -Xprint-suspension for information. From 2c324360cf395c21539674445b418f056ff4cc41 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 14 Feb 2024 10:11:15 +0100 Subject: [PATCH 2/2] Add regression test Closes #19526 --- tests/neg-macros/i19526.check | 6 ++++++ tests/neg-macros/i19526/Macro.scala | 15 +++++++++++++++ tests/neg-macros/i19526/Test.scala | 14 ++++++++++++++ tests/pos-macros/i19526b/Macro.scala | 15 +++++++++++++++ tests/pos-macros/i19526b/Test.scala | 16 ++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 tests/neg-macros/i19526.check create mode 100644 tests/neg-macros/i19526/Macro.scala create mode 100644 tests/neg-macros/i19526/Test.scala create mode 100644 tests/pos-macros/i19526b/Macro.scala create mode 100644 tests/pos-macros/i19526b/Test.scala diff --git a/tests/neg-macros/i19526.check b/tests/neg-macros/i19526.check new file mode 100644 index 000000000000..2ad0a7aa2199 --- /dev/null +++ b/tests/neg-macros/i19526.check @@ -0,0 +1,6 @@ +Cyclic macro dependencies in tests/neg-macros/i19526/Test.scala. +Compilation stopped since no further progress can be made. + +To fix this, place macros in one set of files and their callers in another. + +Compile with -Xprint-suspension for information. diff --git a/tests/neg-macros/i19526/Macro.scala b/tests/neg-macros/i19526/Macro.scala new file mode 100644 index 000000000000..e6861c1986ef --- /dev/null +++ b/tests/neg-macros/i19526/Macro.scala @@ -0,0 +1,15 @@ +package crash.test + +import scala.language.dynamics + +import scala.quoted.* + +object Export extends Dynamic: + inline def applyDynamic(name: "apply")(inline args: Any*): Stack = ${ + applyDynamicImpl('args) + } + + def applyDynamicImpl(args: Expr[Seq[Any]])(using Quotes): Expr[Stack] = + import quotes.reflect.* + + '{ Stack("", Vector.empty) } diff --git a/tests/neg-macros/i19526/Test.scala b/tests/neg-macros/i19526/Test.scala new file mode 100644 index 000000000000..45ae51b664dd --- /dev/null +++ b/tests/neg-macros/i19526/Test.scala @@ -0,0 +1,14 @@ +package crash.test + +case class Stack private[crash] ( + exports: String, + dependsOn: Vector[Int] +) + +trait StackFactory: + val exports: Export.type = Export + + def apply(dependsOn: Int*): Stack = + Export().copy(dependsOn = dependsOn.toVector) + +// nopos-error diff --git a/tests/pos-macros/i19526b/Macro.scala b/tests/pos-macros/i19526b/Macro.scala new file mode 100644 index 000000000000..e6861c1986ef --- /dev/null +++ b/tests/pos-macros/i19526b/Macro.scala @@ -0,0 +1,15 @@ +package crash.test + +import scala.language.dynamics + +import scala.quoted.* + +object Export extends Dynamic: + inline def applyDynamic(name: "apply")(inline args: Any*): Stack = ${ + applyDynamicImpl('args) + } + + def applyDynamicImpl(args: Expr[Seq[Any]])(using Quotes): Expr[Stack] = + import quotes.reflect.* + + '{ Stack("", Vector.empty) } diff --git a/tests/pos-macros/i19526b/Test.scala b/tests/pos-macros/i19526b/Test.scala new file mode 100644 index 000000000000..1cc037298e01 --- /dev/null +++ b/tests/pos-macros/i19526b/Test.scala @@ -0,0 +1,16 @@ +package crash.test + +case class Stack private[crash] ( + exports: String, + dependsOn: Vector[Int] +) + +object Stack: + @annotation.publicInBinary + private[crash] def apply(exports: String, dependsOn: Vector[Int]): Stack = new Stack(exports, dependsOn) + +trait StackFactory: + val exports: Export.type = Export + + def apply(dependsOn: Int*): Stack = + Export().copy(dependsOn = dependsOn.toVector)