Skip to content

Trees quoted macros doesn't resolve the constructor rhs #15842

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

Closed
cchantep opened this issue Aug 10, 2022 · 4 comments
Closed

Trees quoted macros doesn't resolve the constructor rhs #15842

cchantep opened this issue Aug 10, 2022 · 4 comments
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug

Comments

@cchantep
Copy link
Contributor

Compiler version

3.2.1-RC1-bin-20220705-9bb3108-NIGHTLY-git-9bb3108

Minimized code

package test

class Foo(val name: String)

object Bar extends Foo("bar")

object Macros {
  import scala.quoted.{Expr, Quotes, Type}

  inline def show[A]: String = ${ showImpl[A] }

  def showImpl[A](using tpe: Type[A], q: Quotes): Expr[String] = {
    import q.reflect.*

    val repr = TypeRepr.of[A](using tpe)

    val tpeSym = repr.typeSymbol

    Expr(tpeSym.tree.show)
  }
}

Output

> _root_.test.Macros.show[_root_.test.Bar.type]

val res0: String = @scala.annotation.internal.SourceFile("macros/src/main/scala-3/enumeratum/Foo.scala") object Bar extends test.Foo { this: test.Bar.type =>

}

Expectation

Following Tree should be resolved from the super call.

Literal(Constant("bar"))

Alternatives

Having the macro from the reproducer in a separate file doesn't help (same result).

Using repr.typeSymbol.companionModule instead of repr.typeSymbol resolves as bellow:

"lazy val Bar: test.Bar.type"

Try repr.typeSymbol.primaryConstructor doesn't help much:

"def this()"

Even trying to patter-match on it:

tpeSym.tree match {
  case DefDef(_, _, _, rhs) =>
    println(s"Constructor rhs = $rhs")

  case _ =>
}

// => "Constructor rhs = None"
@cchantep cchantep added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 10, 2022
@cchantep
Copy link
Contributor Author

Maybe related to #15799

@nicolasstucki nicolasstucki added 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 labels Aug 11, 2022
@cchantep
Copy link
Contributor Author

Cause may be same as for #14195 but none of the workaround is sufficient

@cchantep
Copy link
Contributor Author

That's quite a blocker.
I'm trying to debug it, but there is no test that can be easily executed while developing quotes impl in this code base.

@cchantep
Copy link
Contributor Author

cchantep commented Sep 2, 2022

Confirmed to be related to -Yretain-trees

@cchantep cchantep closed this as completed Sep 2, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants