Skip to content

ClassInfo exposed via a typeMember call on a sealedType/enum #22052

@jchyb

Description

@jchyb

Compiler version

main (10bb2e6)

Minimized code

Macro_1.scala

import scala.quoted.*

object Macros {
  def testImpl(using Quotes): Expr[Unit] = {
    import quotes.reflect.*

    val barSymbol = TypeRepr.of[domain.Bar].typeSymbol
    val typeMemberClassInfo = TypeRepr.of[domain.Foo].memberType(barSymbol)
    println(typeMemberClassInfo)

    '{()}
  }

  inline def test: Unit = ${ testImpl }
}

object domain {
  sealed trait Foo
  case class Bar() extends Foo
}

Test_2.scala:

@main def main = Macros.test

Output

ClassInfo(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),module class domain$)), class Bar, List(TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object), TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),module class domain$)),trait Foo), TypeRef(TermRef(TermRef(NoPrefix,object _root_),object scala),trait Product), TypeRef(ThisType(TypeRef(NoPrefix,module class io)),trait Serializable)))

Expectation

ClassInfo should never be exposed in the quotes reflection API. directly calling TypeRepr.of[domain.Bar], we get TypeRef(TermRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <root>)),module class <empty>)),domain),Bar), which is a result I would expect there instead of ClassInfo.

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