You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//>usingscala"3.3.1-RC1-bin-20230425-c9ca7ce-NIGHTLY"importscala.quoted.*abstractclassFoo:deftest:StringinlinedefshowExpr(inlinevalue: Any):String=${showExprImpl('value)}
defshowExprImpl(expr: Expr[Any])(usingQuotes):Expr[String] =importquotes.reflect.*Expr(
s"""${expr.asTerm.show}
| |${expr.asTerm.show(usingPrinter.TreeStructure)}""".stripMargin)
inlinedefgenerateFooOverride:Foo=${generateFooImpl}
defgenerateFooImpl(usingQuotes):Expr[Foo] =importquotes.reflect.*valfooRepr=TypeRepr.of[Foo]
valfooSymbol= fooRepr.dealias.classSymbol.get
valoverridingSymbol=Symbol.newClass(Symbol.spliceOwner, Symbol.freshName("Foo"), List(fooRepr), _ =>Nil, None)
defnewInstance(clazz: Symbol, args: List[Term]):Term=Apply(Select(New(TypeTree.ref(clazz)), clazz.primaryConstructor), args)
valfooTestSymbol= fooSymbol.declaredMethod("test").head
valoverridingTestSymbol= fooTestSymbol.overridingSymbol(overridingSymbol)
println(fooTestSymbol.flags.is(Flags.Private).toString) //false as expected
println(fooTestSymbol.isClassConstructor.toString) //false as expected
println(fooTestSymbol.maybeOwner.isClassDef.toString) //true as expected
println(overridingSymbol.isClassDef.toString) //true as expected
println(overridingTestSymbol.isNoSymbol.toString) //true but should be falsedefoverridingTestDef(term: Term):DefDef=DefDef( //java.lang.AssertionError: assertion failed: expected a term symbol but received val <none>
overridingTestSymbol,
_ =>Some(term)
)
defoverridingClassDef(term: Term):ClassDef=ClassDef(
overridingSymbol,
List(newInstance(fooSymbol, Nil)),
List(overridingTestDef(term))
)
definstance(term: Term):Term=Block(
List(overridingClassDef(term)),
newInstance(overridingSymbol, Nil)
)
instance(Literal(StringConstant("hello"))).asExprOf[Foo]
In another file call generateFooOverride
Output
overridingTestSymbol is NoSymbol causing the DefDef in overridingTestDef to throw the following error:
[error] java.lang.AssertionError: assertion failed: expected a term symbol but received val<none>
[error] at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] at scala.quoted.runtime.impl.QuotesImpl$reflect$DefDef$.apply(QuotesImpl.scala:279)
[error] at scala.quoted.runtime.impl.QuotesImpl$reflect$DefDef$.apply(QuotesImpl.scala:278)
[error] at ClassGen$package$.overridingTestDef$1(ClassGen.scala:41)
[error] at ClassGen$package$.overridingClassDef$1(ClassGen.scala:48)
[error] at ClassGen$package$.instance$1(ClassGen.scala:53)
[error] at ClassGen$package$.generateFooImpl(ClassGen.scala:57)
Expectation
I'd expect overridingTestSymbol to not be NoSymbol and generate this code:
I use the low-level term API because in my current use case I need to generate this code for a generic type (T instead of Foo). I'm trying to reproduce this macro.
After diving into the compiler codebase, I checked if my arguments satisfy the criterias needed by Symbol#overridingSymbol (see line 34). They all pass.
The text was updated successfully, but these errors were encountered:
Compiler version
3.3.1-RC1-bin-20230425-c9ca7ce-NIGHTLY
Minimized code
In another file call
generateFooOverride
Output
overridingTestSymbol
isNoSymbol
causing theDefDef
inoverridingTestDef
to throw the following error:Expectation
I'd expect
overridingTestSymbol
to not beNoSymbol
and generate this code:mostly like:
Notes
T
instead ofFoo
). I'm trying to reproduce this macro.Symbol#overridingSymbol
(see line 34). They all pass.The text was updated successfully, but these errors were encountered: