Skip to content
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

-Xcheck-macros does not handle correctly creating instance of local case class #18911

Closed
WojciechMazur opened this issue Nov 13, 2023 · 3 comments · Fixed by #18923
Closed

-Xcheck-macros does not handle correctly creating instance of local case class #18911

WojciechMazur opened this issue Nov 13, 2023 · 3 comments · Fixed by #18923
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:invalid

Comments

@WojciechMazur
Copy link
Contributor

Based on Open Community Build failure for tinkoff/phobos build logs due to usage of scalatest/scalatest macros of which macro implementation was minimized.

Compiler version

Last good release: 3.3.1-RC1-bin-20230524-5262680-NIGHTLY
First bad release: 3.3.1-RC1-bin-20230525-2e19304-NIGHTLY

Commit-based bisect - WIP

Minimized code

// main.scala 

//> using options -Xcheck-macros 

@main def Test = {
  case class Document()
  val expected: Document = ???
  Assertions.assert( expected == Document()) // error
}
// macros.scala
import scala.quoted._
import scala.compiletime.testing.{typeChecks, typeCheckErrors}

trait Assertion
trait Bool {
  def value: Boolean
}
class SimpleMacroBool(expression: Boolean) extends Bool {
  override def value: Boolean = expression
}
class BinaryMacroBool(left: Any, operator: String, right: Any, expression: Boolean) extends Bool {
  override def value: Boolean = expression
}
object Bool {
  def simpleMacroBool(expression: Boolean): Bool = new SimpleMacroBool(expression)
  def binaryMacroBool(left: Any, operator: String, right: Any, expression: Boolean): Bool =
    new BinaryMacroBool(left, operator, right, expression)
  def binaryMacroBool(left: Any, operator: String, right: Any, bool: Bool): Bool =
    new BinaryMacroBool(left, operator, right, bool.value)
}

object Assertions {
  inline def assert(inline condition: Boolean): Assertion =
    ${ AssertionsMacro.assert('{ condition }) }
}

object AssertionsMacro {
  def assert(condition: Expr[Boolean])(using Quotes): Expr[Assertion] =
    transform(condition)

  def transform(
      condition: Expr[Boolean]
  )(using Quotes): Expr[Assertion] = {
    val bool = BooleanMacro.parse(condition)
    '{
      new Assertion {
        val condition = $bool
      }
  }
  }
}

object BooleanMacro {
  private val supportedBinaryOperations =
    Set("!=", "==")

  def parse(condition: Expr[Boolean])(using Quotes): Expr[Bool] = {
    import quotes.reflect._
    import quotes.reflect.ValDef.let
    import util._

    def exprStr: String = condition.show
    def defaultCase = '{ Bool.simpleMacroBool($condition) }

    def isByNameMethodType(tp: TypeRepr): Boolean = tp.widen match {
      case MethodType(_, ByNameType(_) :: Nil, _) => true
      case _                                      => false
    }

    condition.asTerm.underlyingArgument match {
      case Apply(sel @ Select(lhs, op), rhs :: Nil) =>
        def binaryDefault =
          if (isByNameMethodType(sel.tpe)) defaultCase
          else if (supportedBinaryOperations.contains(op)) {
            let(Symbol.spliceOwner, lhs) { left =>
              let(Symbol.spliceOwner, rhs) { right =>
                val app = left.select(sel.symbol).appliedTo(right)
                let(Symbol.spliceOwner, app) { result =>
                  val l = left.asExpr
                  val r = right.asExpr
                  val b = result.asExprOf[Boolean]
                  val code = '{ Bool.binaryMacroBool($l, ${ Expr(op) }, $r, $b) }
                  code.asTerm
                }
              }
            }.asExprOf[Bool]
          } else defaultCase

        op match {
          case "==" => binaryDefault
          case _    => binaryDefault
        }

      case Literal(_) =>
        '{ Bool.simpleMacroBool($condition) }

      case _ =>
        defaultCase
    }
  }
}

Output

-- Error: /Users/wmazur/projects/dotty/bisect/main.scala:6:19 ------------------
 6 |  Assertions.assert( expected == Document()) // error
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |Malformed tree was found while expanding macro with -Xcheck-macros.
   |               |The tree does not conform to the compiler's tree invariants.
   |               |
   |               |Macro was:
   |               |scala.quoted.runtime.Expr.splice[Assertion](((evidence$1: scala.quoted.Quotes) ?=> AssertionsMacro.assert(scala.quoted.runtime.Expr.quote[scala.Boolean](expected.==(Document.apply())).apply(using evidence$1))(evidence$1)))
   |               |
   |               |The macro returned:
   |               |{
   |  final class $anon() extends Assertion {
   |    val condition: Bool = {
   |      val x: Document = expected
   |      val `x₂`: Document = new Document().apply()
   |      val `x₃`: scala.Boolean = x.==(`x₂`)
   |      Bool.binaryMacroBool(x, "==", `x₂`, `x₃`)
   |    }
   |  }
   |
   |  (new $anon(): Assertion)
   |}
   |               |
   |               |Error:
   |               |assertion failed: new of object Document module should only exist in object Document but was in value x
   |               |

Macro stacktrace

Compiling project (Scala 3.4.0-RC1-bin-20231109-c7b3d7b-NIGHTLY, JVM)
[error] ./main.scala:6:3
[error] Malformed tree was found while expanding macro with -Xcheck-macros.
[error]                |The tree does not conform to the compiler's tree invariants.
[error]                |
[error]                |Macro was:
[error]                |scala.quoted.runtime.Expr.splice[Assertion](((contextual$1: scala.quoted.Quotes) ?=> AssertionsMacro.assert(scala.quoted.runtime.Expr.quote[scala.Boolean](expected.==(Document.apply())).apply(using contextual$1))(contextual$1)))
[error]                |
[error]                |The macro returned:
[error]                |{
[error]   final class $anon() extends Assertion {
[error]     val condition: Bool = {
[error]       val x: Document = expected
[error]       val `x₂`: Document = new Document().apply()
[error]       val `x₃`: scala.Boolean = x.==(`x₂`)
[error]       Bool.binaryMacroBool(x, "==", `x₂`, `x₃`)
[error]     }
[error]   }
[error] 
[error]   (new $anon(): Assertion)
[error] }
[error]                |
[error]                |Error:
[error]                |assertion failed: new of object Document module should only exist in object Document but was in value x
[error]                |  scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedNew(TreeChecker.scala:507)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3136)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.ReTyper.typedSelect(ReTyper.scala:42)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedSelect(TreeChecker.scala:484)  
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3101)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3409)  
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:958)  
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1118)  
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedApply(TreeChecker.scala:515)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.ReTyper.typedSelect(ReTyper.scala:42)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedSelect(TreeChecker.scala:484)  
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3101)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3409)  
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:958)  
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1118)  
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedApply(TreeChecker.scala:515)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3409)  
[error] dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2511)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedValDef(TreeChecker.scala:585)  
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3319)  
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3365)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:654)  
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1182)  
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1186)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:248)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:276)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:636)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3140)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3290)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3409)  
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1189)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:248)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:276)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:636)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3140)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined$$anonfun$1(TreeChecker.scala:639)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:248)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined(TreeChecker.scala:639)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3155)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3409)  
[error] dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2511)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedValDef(TreeChecker.scala:585)  
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3319)  
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3365)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:654)  
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2761)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:581)  
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3120)  
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3124)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3319)  
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3365)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:654)  
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1182)  
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1186)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:248)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:636)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:276)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:636)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3140)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined$$anonfun$1(TreeChecker.scala:639)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:248)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined(TreeChecker.scala:639)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3155)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:398)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3290)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:381)  
[error] dotty.tools.dotc.transform.TreeChecker$.checkMacroGeneratedTree(TreeChecker.scala:806)  
[error] dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSplice(Inliner.scala:840)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3177)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:919)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:65)  
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3137)  
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216)  
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)  
[error] dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:919)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3290)  
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297)  
[error] dotty.tools.dotc.inlines.Inliner.inlined(Inliner.scala:681)  
[error] dotty.tools.dotc.inlines.Inlines$InlineCall.expand(Inlines.scala:466)  
[error] dotty.tools.dotc.inlines.Inlines$.inlineCall(Inlines.scala:152)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:96)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1256)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1238)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1251)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1256)  
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1547)  
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:43)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:92)  
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:50)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:90)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1251)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1251)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1253)  
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:58)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:109)  
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1601)  
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:67)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:90)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1251)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1251)  
[error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1253)  
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1612)  
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:67)  
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:98)  
[error] dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:59)  
[error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:18)  
[error] dotty.tools.dotc.transform.Inlining.run(Inlining.scala:35)  
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:345)  
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)  
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)  
[error] scala.collection.immutable.List.foreach(List.scala:333)  
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:351)  
[error] dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:39)  
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)  
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)  
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)  
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)  
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:337)  
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)  
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)  
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)  
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:357)  
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:267)  
[error] dotty.tools.dotc.Driver.finish(Driver.scala:58)  
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:38)  
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)  
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)  
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)  
[error] sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)  
[error] sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:155)  
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)  
[error] sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)  
[error] bloop.tracing.BraveTracer.traceInternal(BraveTracer.scala:67)  
[error] bloop.tracing.BraveTracer.trace(BraveTracer.scala:41)  
[error] sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)  
[error] sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:155)  
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)  
[error] monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)  
[error] monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)  
[error] monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)  
[error] monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)  
[error] java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)  
[error] java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)  
[error] java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)  
[error] java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)  
[error] java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)  
[error] java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
[error]                |
[error]   Assertions.assert( expected == Document()) // error
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.4.0-RC1-bin-20231109-c7b3d7b-NIGHTLY, JVM)

Expectation

Should not couse error when compiling. Constructor of case class is public and used in the same, local scope.

@WojciechMazur WojciechMazur added itype:bug area:metaprogramming:quotes Issues related to quotes and splices labels Nov 13, 2023
@WojciechMazur WojciechMazur changed the title -XcheckMacros does not handle correctly creating instance of local class -Xcheck-macros does not handle correctly creating instance of local case class Nov 13, 2023
@WojciechMazur
Copy link
Contributor Author

The commit-based bisect points to 61190e6
Also, it's interesting that Document() is transformed to new Document().apply() - it might suggest incorrect transformation, altough I'm not sure why it happens at first place.

@nicolasstucki
Copy link
Contributor

It seems like the checks in 61190e6 correctly find the inconsistent tree new Document().apply(). This is a New(Ident(Document$)) outside of the lazy val for the object Document.

@nicolasstucki
Copy link
Contributor

The macro has an undefined behaviour due to the use os underlyingArgument. They are using the result of this method in generated code. They must remove that in their implementation.

We could try to patch this particular use case.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 14, 2023
odersky added a commit that referenced this issue Nov 28, 2023
Do not look under RHS of the `lazy val` of an object.

Fixes #18911
WojciechMazur pushed a commit that referenced this issue Jun 24, 2024
WojciechMazur pushed a commit that referenced this issue Jun 24, 2024
WojciechMazur pushed a commit that referenced this issue Jun 24, 2024
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:invalid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants