Skip to content

ClassInfo can appear as result of memberType in macros #13319

Open
@scf37

Description

@scf37

Compiler version

3.0.1

Minimized code

import scala.quoted._
object Macro:
  inline def apply[A]: Unit = ${impl[A]}

  private def impl[A: Type](using Quotes): Expr[String] =
    import quotes.reflect._
    val t = TypeRepr.of[A]
    Expr.ofList(t.baseClasses.drop(1).filter(_.flags.is(Flags.Trait)).map { baseSymbol =>
        t.memberType(baseSymbol).asType  match { case '[t] => 42}
        Expr("")
    })
    Expr("")
Macro[Option[String]]

Output (click arrow to expand)

[info] compiling 2 Scala sources to /tmp/1/target/scala-3.0.1/classes ...
[info] assertion failure for trait Serializable in package java.io <:< t, frozen = false
[error] -- Error: /tmp/1/Main.scala:6:9 ------------------------------------------------
[error] 6 |    Macro[Option[String]]
[error]   |    ^^^^^^^^^^^^^^^^^^^^^
[error]   |Exception occurred while executing macro expansion.
[error]   |java.lang.AssertionError: assertion failed: ClassInfo(ThisType(TypeRef(NoPrefix,module class io)), trait Serializable, List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)))
[error]   |	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error]   |	at dotty.tools.dotc.core.Types$TypeBounds.<init>(Types.scala:4791)
[error]   |	at dotty.tools.dotc.core.Types$RealTypeBounds.<init>(Types.scala:4852)
[error]   |	at dotty.tools.dotc.core.Types$TypeBounds$.apply(Types.scala:4896)
[error]   |	at dotty.tools.dotc.core.Types$TypeBounds.derivedTypeBounds(Types.scala:4799)
[error]   |	at dotty.tools.dotc.core.ConstraintHandling.addOneBound(ConstraintHandling.scala:108)
[error]   |	at dotty.tools.dotc.core.ConstraintHandling.addOneBound$(ConstraintHandling.scala:26)
[error]   |	at dotty.tools.dotc.core.ProperGadtConstraint.addOneBound(GadtConstraint.scala:60)
[error]   |	at dotty.tools.dotc.core.ConstraintHandling.addBoundTransitively(ConstraintHandling.scala:162)
[error]   |	at dotty.tools.dotc.core.ConstraintHandling.addBoundTransitively$(ConstraintHandling.scala:26)
[error]   |	at dotty.tools.dotc.core.ProperGadtConstraint.addBoundTransitively(GadtConstraint.scala:60)
[error]   |	at dotty.tools.dotc.core.ProperGadtConstraint.addBound(GadtConstraint.scala:159)
[error]   |	at dotty.tools.dotc.core.TypeComparer.gadtAddLowerBound(TypeComparer.scala:118)
[error]   |	at dotty.tools.dotc.core.TypeComparer.narrowGADTBounds(TypeComparer.scala:1870)
[error]   |	at dotty.tools.dotc.core.TypeComparer.compareGADT$1(TypeComparer.scala:505)
[error]   |	at dotty.tools.dotc.core.TypeComparer.thirdTryNamed$1(TypeComparer.scala:508)
[error]   |	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:557)
[error]   |	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:488)
[error]   |	at dotty.tools.dotc.core.TypeComparer.compareNamed$1(TypeComparer.scala:297)
[error]   |	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:303)
[error]   |	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1282)
[error]   |	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:185)
[error]   |	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:195)
[error]   |	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
[error]   |	at dotty.tools.dotc.core.TypeComparer$.topLevelSubType(TypeComparer.scala:2673)
[error]   |	at dotty.tools.dotc.core.Types$Type.$less$colon$less(Types.scala:1032)
[error]   |	at scala.quoted.runtime.impl.QuoteMatcher$.$eq$qmark$eq(QuoteMatcher.scala:336)
[error]   |	at scala.quoted.runtime.impl.QuoteMatcher$.treeMatch(QuoteMatcher.scala:129)
[error]   |	at scala.quoted.runtime.impl.QuotesImpl.scala$quoted$runtime$impl$QuotesImpl$$treeMatch(QuotesImpl.scala:2961)
[error]   |	at scala.quoted.runtime.impl.QuotesImpl$TypeMatch$.unapply(QuotesImpl.scala:2931)
[error]   |	at Macro$.impl$$anonfun$2(Macro.scala:9)
[error]   |	at scala.collection.immutable.List.map(List.scala:246)
[error]   |	at Macro$.impl(Macro.scala:10)
[error]   |	at Macro$.inline$impl(Macro.scala:5)
[error]   |
[error]   | This location contains code that was inlined from Main.scala:6
[error] one error found
[error] one error found

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions