Skip to content

-Yretain-trees (and flags which imply it like -Ysafe-init) changes the types of trees returned by the reflection API #14195

Open
@cchantep

Description

@cchantep

Compiler version

3.1.2-RC1-bin-20211222-c94b333-NIGHTLY

Minimized code

🤚 With -Ysafe-init in scalacOptions

import scala.deriving.Mirror
import scala.quoted.*
import scala.reflect.ClassTag

inline def test[A]: Unit = ${ testImpl[A] }

private def testImpl[A](
  using
    q: Quotes,
  t: Type[A]
): Expr[Unit] = {
  import q.reflect.*

  val tpr = TypeRepr.of[A]

  tpr.classSymbol.foreach {
    _.tree match {
      case cd: ClassDef =>
        val tpe = cd.constructor.returnTpt.tpe

        println(s"classTpe = ${tpe.show}")

      case _ =>
    }
  }

  '{ () }
}

// Execute test below:

final class Foo(val name: String)

test[Foo]

Output

classTpe = scala.Unit

Expectation

classTpe = Foo

⚠️ Expected result ok without -Ysafe-init

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