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

Ref(companionModule) produces wrong references for local classes #14574

Open
NTPape opened this issue Feb 26, 2022 · 0 comments
Open

Ref(companionModule) produces wrong references for local classes #14574

NTPape opened this issue Feb 26, 2022 · 0 comments
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug

Comments

@NTPape
Copy link

NTPape commented Feb 26, 2022

Compiler version

3.1.1

Minimized code

trait CompilationTest:

  case class A(s: A.S):
    MinimalExample.test(s)

  object A:
    case class S(bar: Int)

  val a = A(A.S(42))

object CompilationTestImpl extends CompilationTest
object MinimalExample:
  inline def test[T](t: T): Unit = ${ testImpl('t) }

  private def testImpl[T](expr: Expr[T])(using Quotes): Expr[Any] = {

    import quotes.reflect.*

    val companionRef = Ref(expr.asTerm.tpe.classSymbol.get.companionModule)
    Select.unique(companionRef, "unapply").appliedTo(expr.asTerm).asExpr
  }

Output

java.lang.AssertionError: assertion failed: failure to construct path from value <local A>/class A/trait CompilationTest/package <empty>/package <root> to `this` of object A in trait CompilationTest;

because companionRef points to A.this.S instead of A.S

Expectation

One can construct valid references to companions of local classes. (Make CompilationTest an object and it works.)
Might be related to #14508.

@NTPape NTPape added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 26, 2022
@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 Feb 27, 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