Hi folks,
I have strange behavior with implicit macro.
When I use it on type defined inside object - works fine (generated Transformer instance is correct).
Example:
class TransformerSpec extends WordSpecLike {
....
"parse to instance of case class defined inside module" in {
import TypeHolder.Point
val cfg = ConfigFactory.parseString("""point = {x = 1, y= 2}""")
val tr = implicitly[Transformer[Point]]
val pl = tr("point", cfg)
val pr = Point(x = 1, y = 2)
assert(pl == pr)
}
In this case Point is defined in separate object:
object TypeHolder {
case class Point(x:Int, y:Int)
}
But when I use inheritance like this:
trait TypeHolder {
case class Point(x:Int, y:Int)
}
class TransformerSpec extends WordSpecLike with TypeHolder {
....
the same (just import) code finish with compilation error:
[info] Compiling 1 Scala source to /data/work/akkamo/akkamo/akkamoConfigMacro/target/scala-2.12/test-classes…
[error] /data/work/akkamo/akkamo/akkamoConfigMacro/src/test/scala/eu/akkamo/m/config/TransformerSpec.scala:64: type mismatch;
[error] found : TypeHolder.this.Point
[error] required: TransformerSpec.this.Point
[error] val tr = implicitly[Transformer[Point]]
Generated macro code:
{
final class $anon extends eu.akkamo.m.config.TransformerGenerator.AT[TransformerSpec.this.Point] {
def <init>() = {
looks fine. (Remark: trait AT[T] extends Transformer[T] )
I use Scala 2.12.2.
Whole example is located here: akkamoConfigMacro
Any advice? It looks like a bug in the compiler, but I hope the problem is in my code - of course.
thanks for any advice
Juraj