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

Referencing a tree of an inner class leads to a ClassCastException #19732

Closed
lbialy opened this issue Feb 19, 2024 · 6 comments · Fixed by #19930
Closed

Referencing a tree of an inner class leads to a ClassCastException #19732

lbialy opened this issue Feb 19, 2024 · 6 comments · Fixed by #19930
Assignees
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug itype:crash
Milestone

Comments

@lbialy
Copy link

lbialy commented Feb 19, 2024

Compiler version

3.3.1

Minimized code

This is a slightly changed code from https://github.com/lampepfl/dotty-macro-examples/tree/main/defaultParamsInference, two files as in the example:

macro.scala:

package dummy

import scala.quoted.*

trait Defaults[A]:
  def defaults: Map[String, Any]

object Defaults:
  inline def derived[A <: Product]: Defaults[A] = ${ defaultsImpl[A] }

  def defaultsImpl[A <: Product: Type](using Quotes): Expr[Defaults[A]] =
    '{
      new Defaults[A]:
        def defaults: Map[String, Any] = ${ defaultParmasImpl[A] }
    }

inline def defaultParams[T]: Map[String, Any] = ${ defaultParmasImpl[T] }

def defaultParmasImpl[T](using quotes: Quotes, tpe: Type[T]): Expr[Map[String, Any]] =
  import quotes.reflect.*
  TypeRepr.of[T].classSymbol match
    case None => '{ Map.empty[String, Any] }
    case Some(sym) =>
      val comp = sym.companionClass
      val mod = Ref(sym.companionModule)
      val names =
        for p <- sym.caseFields if p.flags.is(Flags.HasDefault)
        yield p.name
      val namesExpr: Expr[List[String]] =
        Expr.ofList(names.map(Expr(_)))

      val body = comp.tree.asInstanceOf[ClassDef].body
      val idents: List[Ref] =
        for
          case deff @ DefDef(name, _, _, _) <- body
          if name.startsWith("$lessinit$greater$default")
        yield mod.select(deff.symbol)
      val typeArgs = TypeRepr.of[T].typeArgs
      val identsExpr: Expr[List[Any]] =
        if typeArgs.isEmpty then Expr.ofList(idents.map(_.asExpr))
        else Expr.ofList(idents.map(_.appliedToTypes(typeArgs).asExpr))

      '{ $namesExpr.zip($identsExpr).toMap }

dummy.scala:

package dummy

case class Person(name: String, address: String = "Zuricch", foo: Int, age: Int = 26)
case class Test3[A, B](as: List[A], bs: List[B] = List.empty)

object Person:
  val x = 10

class Outer:
  case class Inner(a: String, b: Int = 23) derives Defaults

@main def test(): Unit =
  val p1 = Person("John", foo = 10)
  val t1 = Test3(List("string"), List(23.0))
  println(p1)
  println(t1)
  println(defaultParams[Person])
  println(defaultParams[Test3[String, Double]])
  assert(defaultParams[Person] == Map("address" -> "Zuricch", "age" -> 26))

  val outer = Outer()
  println(summon[Defaults[outer.Inner]].defaults)

How to run:

  • place both files in an empty directory
  • run scala-cli run . -S 3.3.1 --server=false

For some reason this does not happen when using the defaultParams macro directly but does happen if the same macro is executed via macro called by derives. Only happens for inner classes, other cases seem to work fine.

Output (click arrow to expand)

-- Error: /Users/lbialy/Projects/foss/tmp/macros/dummy.scala:10:51 -------------
10 |  case class Inner(a: String, b: Int = 23) derives Defaults
   |                                                   ^
   |Exception occurred while executing macro expansion.
   |java.lang.ClassCastException: class dotty.tools.dotc.ast.Trees$This cannot be cast to class dotty.tools.dotc.ast.Trees$RefTree (dotty.tools.dotc.ast.Trees$This and dotty.tools.dotc.ast.Trees$RefTree are in unnamed module of loader 'app')
   |	at scala.quoted.runtime.impl.QuotesImpl.scala$quoted$runtime$impl$QuotesImpl$reflect$Ref$$$_$apply$$anonfun$6(QuotesImpl.scala:445)
   |	at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$withDefaultPos(QuotesImpl.scala:2997)
   |	at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:445)
   |	at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:443)
   |	at dummy.macro$package$.defaultParmasImpl(macro.scala:25)
   |	at dummy.Defaults$.defaultsImpl$$anonfun$1(macro.scala:14)
   |	at dummy.Defaults$.defaultsImpl$$anonfun$adapted$1(macro.scala:14)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:110)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1538)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1570)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1605)
   |	at scala.collection.immutable.List.mapConserve(List.scala:472)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1605)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1601)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1574)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1572)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1605)
   |	at scala.collection.immutable.List.mapConserve(List.scala:472)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1605)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1601)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformBlock(Trees.scala:1603)
   |	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1518)
   |	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135)
   |	at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:152)
   |	at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:88)
   |	at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3143)
   |	at dummy.Defaults$.defaultsImpl(macro.scala:14)
   |
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from macro.scala:9
 9 |  inline def derived[A <: Product]: Defaults[A] = ${ defaultsImpl[A] }
   |                                                  ^^^^^^^^^^^^^^^^^^^^
    ----------------------------------------------------------------------------
1 error found
Compilation failed
@lbialy lbialy added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 19, 2024
@Kordyjan Kordyjan added area:metaprogramming:quotes Issues related to quotes and splices area:metaprogramming:reflection Issues related to the quotes reflection API and removed stat:needs triage Every issue needs to have an "area" and "itype" label area:metaprogramming:quotes Issues related to quotes and splices labels Feb 19, 2024
@nicolasstucki nicolasstucki assigned Kordyjan, mbovel and jchyb and unassigned jchyb, Kordyjan and mbovel Feb 19, 2024
@jchyb
Copy link
Contributor

jchyb commented Mar 11, 2024

Minimised:

class Outer:
  case class Inner(b: Int = 23) derives Defaults
import scala.quoted.*

trait Defaults[A]:
  def defaults: Map[String, Any]

object Defaults:
  inline def derived[A <: Product]: Defaults[A] = ${ defaultsImpl[A] }

  def defaultsImpl[A <: Product: Type](using Quotes): Expr[Defaults[A]] =
    '{
      new Defaults[A]:
        def defaults: Map[String, Any] = ${ defaultParmasImpl[A] }
    }

inline def defaultParams[T]: Map[String, Any] = ${ defaultParmasImpl[T] }

def defaultParmasImpl[T](using quotes: Quotes, tpe: Type[T]): Expr[Map[String, Any]] =
  import quotes.reflect.*
  TypeRepr.of[T].classSymbol match
    case None => '{ Map.empty[String, Any] }
    case Some(sym) =>
      val comp = sym.companionClass
      Ref(sym.companionModule)
      '{???}

With that said, we can also produce a compiler crash in erasure without any derives keywords:

class Outer:
  case class Inner(b: Int = 23)

@main def test(): Unit =
  val outer = Outer()
  defaultParams[outer.Inner]
import scala.quoted.*

inline def defaultParams[T]: Map[String, Any] = ${ defaultParmasImpl[T] }

def defaultParmasImpl[T](using quotes: Quotes, tpe: Type[T]): Expr[Map[String, Any]] =
  import quotes.reflect.*
  TypeRepr.of[T].classSymbol match
    case None => '{ Map.empty[String, Any] }
    case Some(sym) =>
      val comp = sym.companionClass
      val mod = Ref(sym.companionModule)
      val names =
        for p <- sym.caseFields if p.flags.is(Flags.HasDefault)
        yield p.name
      val namesExpr: Expr[List[String]] =
        Expr.ofList(names.map(Expr(_)))

      val body = comp.tree.asInstanceOf[ClassDef].body
      val idents: List[Ref] =
        for
          case deff @ DefDef(name, _, _, _) <- body
          if name.startsWith("$lessinit$greater$default")
        yield mod.select(deff.symbol)
      val typeArgs = TypeRepr.of[T].typeArgs
      val identsExpr: Expr[List[Any]] =
        if typeArgs.isEmpty then Expr.ofList(idents.map(_.asExpr))
        else Expr.ofList(idents.map(_.appliedToTypes(typeArgs).asExpr))

      '{ $namesExpr.zip($identsExpr).toMap }
Exception in thread "main" 
  Exception while compiling macro.scala, main.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: <no file>
        during phase: parser
                mode: Mode()
     library version: version 2.13.12
    compiler version: version 3.4.2-RC1-bin-SNAPSHOT-nonbootstrapped-git-a9bb881
            settings: -classpath /Users/jchyb/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/Users/jchyb/Documents/workspace/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.2-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.2-RC1-bin-SNAPSHOT.jar
java.lang.AssertionError: assertion failed: missing outer accessor in the top-level definitions in package <empty>
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$outerParamAccessor(ExplicitOuter.scala:237)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:474)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:483)
        at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:804)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3124)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3098)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3206)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3098)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3206)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3281)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.$anonfun$45(Typer.scala:2134)
        at dotty.tools.dotc.core.Decorators$.loop$1(Decorators.scala:99)
        at dotty.tools.dotc.core.Decorators$.mapconserve(Decorators.scala:115)
        at dotty.tools.dotc.typer.Typer.typedSeqLiteral(Typer.scala:2134)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSeqLiteral(Erasure.scala:885)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3145)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:856)
        at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:160)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:856)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3123)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)
        at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:904)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:856)
        at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:160)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:856)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3123)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3281)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)
        at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:904)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)
        at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:904)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:856)
        at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:160)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:856)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3123)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3098)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3206)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure$Typer.typedTypeApply(Erasure.scala:816)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3143)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:843)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3123)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)
        at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:904)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.transform.Erasure$Typer.typedTyped(Erasure.scala:633)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3128)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3281)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100)
        at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:904)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3337)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3356)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1197)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1201)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3131)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1204)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3131)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.typer.Typer.$anonfun$63(Typer.scala:2613)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2613)
        at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:960)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3206)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3310)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3356)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2800)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1049)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3111)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3115)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3206)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3310)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3356)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2933)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3157)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3207)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3284)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3288)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3399)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:360)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:267)
        at dotty.tools.dotc.Run.compileSuspendedUnits(Run.scala:371)
        at dotty.tools.dotc.Driver.finish(Driver.scala:57)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
        at dotty.tools.dotc.Driver.process(Driver.scala:196)
        at dotty.tools.dotc.Driver.process(Driver.scala:164)
        at dotty.tools.dotc.Driver.process(Driver.scala:176)
        at dotty.tools.dotc.Driver.main(Driver.scala:206)
        at dotty.tools.dotc.Main.main(Main.scala)

@jchyb
Copy link
Contributor

jchyb commented Mar 12, 2024

The second minimisation I prepared above is a separate issue, where after getting a symbol of a path dependent TypeRepr we lose information about the prefix there, changing back to a typeref we find out that it is now prefixed by this instead of val outer, which is incoherent in that context. This is not as important as the other bug, as this is caught by -Xcheck-macros, but I'll still prepare a separate issue.

@jchyb
Copy link
Contributor

jchyb commented Mar 12, 2024

Submitted the issue: #19933

nicolasstucki added a commit that referenced this issue Mar 14, 2024
#19930)

In the issue minimisation, `tpd.ref` returns a tpd.This(Ident(Inner$))
tree, where the inner ident is a type ident, which was unexpected.
Trying to adjust the `tpd.ref` to return a RefType for that case seems
dangerous, so I instead opted for a workaround directly inside the
QuotesImpl.

At first I wanted to reuse the `tpd.This` tree somehow (or at least to
use a correctly retyped `Ident`), but nothing I tried with it worked, so
I ended up writing the correct Ref by hand.

Fixes #19732
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
WojciechMazur added a commit that referenced this issue Jul 4, 2024
…o `RefTree`" to LTS (#20990)

Backports #19930 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@lbialy
Copy link
Author

lbialy commented Jul 20, 2024

@Kordyjan is this getting a backport to 3.3.x?

@WojciechMazur
Copy link
Contributor

It was backported, can be tried with 3.3.4-RC1

@lbialy
Copy link
Author

lbialy commented Jul 20, 2024

Awesome, both besom and scala-yaml have the workaround. I'll test on 3.3.4-RC1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants