[macros] untypecheck seems to produce invalid code
Stefan Ollinger <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
Hey,
See attached example. Is that a known bug or am I doing something wrong?
Regards,
Stefan
------
import scala.reflect.runtime.universe._
import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
abstract class A {
val is: Int
}
def fooImpl(c: Context)(expr: c.Expr[Any]) = {
import c.universe._
println(expr)
// Expr[Nothing]({
// final class $anon extends $line22.$read.$iw.$iw.$iw.$iw.$iw.$iw.A {
// def <init>(): <$anon: A> = {
// $anon.super.<init>();
// ()
// };
// private[this] val is: Int = 100;
// override <stable> <accessor> def is: Int = $anon.this.is
// };
// new $anon()
// })
val untypedExpr = c.Expr[Any](c.untypecheck(expr.tree.duplicate))
println(untypedExpr) // this is invalid: override private[this] val is = 100;
// Expr[Any]({
// final class $anon extends $line22.$read.$iw.$iw.$iw.$iw.$iw.$iw.A {
// def <init>() = {
// super.<init>();
// ()
// };
// override private[this] val is = 100;
// override <stable> <accessor> def is: Int = $anon.this.is
// };
// new $anon()
// })
untypedExpr
}
def foo(expr: => Any): Any = macro fooImpl
// 1. this does not work
foo {
new A {
override val is = 100
}
}
// <console>:18: error: value is overrides nothing
// override val is = 100
// 2. this works
val tree = reify {
new A {
override val is = 100
}
}
// tree: reflect.runtime.universe.Expr[A] =
// Expr[A]({
// final class $anon extends $read.A {
// def <init>() = {
// super.<init>();
// ()
// };
// override val is = 100
// };
// new $anon()
// })
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.