Skip to content

Regression in zio/zio-prelude - too eager recursive macro dependency check #19604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WojciechMazur opened this issue Feb 3, 2024 · 0 comments · Fixed by #19605
Closed

Regression in zio/zio-prelude - too eager recursive macro dependency check #19604

WojciechMazur opened this issue Feb 3, 2024 · 0 comments · Fixed by #19605
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

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

zio-prelude-reproducer.zip

// 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

@WojciechMazur WojciechMazur added itype:bug regression This worked in a previous version but doesn't anymore area:metaprogramming:quotes Issues related to quotes and splices labels Feb 3, 2024
odersky added a commit to dotty-staging/dotty that referenced this issue Feb 3, 2024
Regular StaleSymbol can be caught and masked in some situations. Stale symbol
type errors need to allow the same.

Fixes scala#19604
nicolasstucki added a commit that referenced this issue Feb 5, 2024
Regular StaleSymbol can be caught and masked in some situations. Stale
symbol type errors need to allow the same.

Fixes #19604
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur pushed a commit that referenced this issue Jun 30, 2024
Regular StaleSymbol can be caught and masked in some situations. Stale symbol
type errors need to allow the same.

Fixes #19604

[Cherry-picked fbffe7b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants