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
TypeDef(TImpl,
Template(
DefDef(
<init>,
List(List(ValDef(toWire,TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)],EmptyTree))),
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class izumi)),class TImpl)],
EmptyTree
),
List(
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object)], TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class izumi)),trait T)]
),
ValDef(_,EmptyTree,EmptyTree),
List(ValDef(toWire,TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)],EmptyTree))
))
and the tree generated by my macro looks like
TypeDef(
TAutoImpl,
Template(
DefDef(
<init>,
List(List(ValDef(toWire,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)],EmptyTree))),
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class izumi)),trait T)],
EmptyTree
),
List(
TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class java)),object lang),Object)],
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class izumi)),trait T)]
),
ValDef(_,EmptyTree,EmptyTree),
List(ValDef(toWire,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)],EmptyTree))
))
So, visually the trees are identical.
Though .show for my tree produces class TAutoImpl(toWire: scala.Int) extends java.lang.Object with izumi.T instead of expected class TAutoImpl(override val toWire: scala.Int). I'm not sure why exactly this happens, but I guess it's somehow related to the empty constructor added by newClass.
I think the API should be improved. It may be more ergonomic and it must be possible to define trees for arbitrary classes.
Another construction which I've been unable to reproduce in a macro was an implementation for an abstract class passing a constructor parameter to parent's constructor:
// I have this
abstract class AnAbstractClass(c: Int) {
def toWire: String
// def bullshit(a: Int): String
def xxx: String = ""
}
// need to generate this:
class AClass2(cparam: Int) extends AnAbstractClass(cparam) {
override def toWire: String = "xxx"
}
The text was updated successfully, but these errors were encountered:
I'm trying to build a macro which, for given trait
T
would generate an implementation:It seems that the only way to create a
Symbol
for a class isSymbol.newClass
method, which addes an empty constructor into the newly created Symbol. Also it looks like there is no way to remove that constructor.So, I'm able to build a tree which looks exactly as one generated by the compiler with the following crappy code:
The tree generated by the compiler looks like
and the tree generated by my macro looks like
So, visually the trees are identical.
Though
.show
for my tree producesclass TAutoImpl(toWire: scala.Int) extends java.lang.Object with izumi.T
instead of expectedclass TAutoImpl(override val toWire: scala.Int)
. I'm not sure why exactly this happens, but I guess it's somehow related to the empty constructor added bynewClass
.I think the API should be improved. It may be more ergonomic and it must be possible to define trees for arbitrary classes.
Another construction which I've been unable to reproduce in a macro was an implementation for an abstract class passing a constructor parameter to parent's constructor:
The text was updated successfully, but these errors were encountered: