Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
Closes #19526
  • Loading branch information
nicolasstucki committed Feb 14, 2024
1 parent cc69895 commit 2c32436
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/neg-macros/i19526.check
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions tests/neg-macros/i19526/Macro.scala
Original file line number Diff line number Diff line change
@@ -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) }
14 changes: 14 additions & 0 deletions tests/neg-macros/i19526/Test.scala
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/pos-macros/i19526b/Macro.scala
Original file line number Diff line number Diff line change
@@ -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) }
16 changes: 16 additions & 0 deletions tests/pos-macros/i19526b/Test.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2c32436

Please sign in to comment.