Closed
Description
Based on OpenCB failure for zio/zio-prelude
build logs
It was compiling in Scala 3.3.x without compiler crash.
Compiler version
Last good release: 3.4.1-RC1-bin-20240129-b20747d-NIGHTLY
First bad release: 3.4.1-RC1-bin-20240130-7a5cb6e-NIGHTLY
Bisect points to: e4e1c57
Minimized code
// prelude.scala
import prelude.newtypes.Natural
package object prelude extends ZSetSyntax {
type MultiSet[+A] = ZSet[A, Natural]
val MultiSet: ZSet.type = ZSet
}
// ZSet.scala
// moving it to core.scala would lead to Recursion limit exceeded: find-member prelude.ZSetSyntax
package prelude
import prelude.newtypes._
class ZSet[+A, +B]
object ZSet
trait ZSetSyntax {
implicit final class ZSetMapOps[+A](self: Map[A, Natural])
}
// core.scala
package prelude
sealed trait Assertion[-A]
object Assertion:
def greaterThanOrEqualTo[A](value: A): Assertion[A] = ???
sealed trait AssertionError
abstract class NewtypeCustom[A] {
type Type
protected inline def validateInline(inline value: A): Unit
inline def apply(inline a1: A): Type = {
validateInline(a1)
a1.asInstanceOf[Type]
}
}
abstract class Newtype[A] extends NewtypeCustom[A] {
def assertion: Assertion[A] = ???
protected inline def validateInline(inline value: A): Unit = ${
Macros.validateInlineImpl[A]('assertion, 'value)
}
}
abstract class Subtype[A] extends Newtype[A] {
type Type <: A
}
package object newtypes {
type Natural = Natural.Type
object Natural extends Subtype[Int] {
override inline def assertion = Assertion.greaterThanOrEqualTo(0)
val one: Natural = Natural(1) // triggers macro
}
}
// macro.scala
package prelude
import scala.quoted.*
object Macros {
def validateInlineImpl[A: Type](assertionExpr: Expr[Assertion[A]], a: Expr[A])(using Quotes): Expr[Unit] =
'{ () }
}
Output
-- Error: /Users/wmazur/projects/sandbox/core.scala:21:33 ----------------------
21 | Macros.validateInlineImpl[A]('assertion, 'value)
| ^
|Cyclic macro dependency; macro refers to a toplevel symbol in /Users/wmazur/projects/sandbox/core.scala from which the macro is called
1 error found
Expectation
Should allow to compile