diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-12-08 16:28:41 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-12-10 10:29:02 +0100 |
commit | 87979ad96f3a07354be4c15cdf35f71d1d4739cb (patch) | |
tree | aca34d4bec9a31a44c1a81d18a4701ef8ceb4231 /test/files/run/macro-def-path-dependent | |
parent | 75cc6cf256df9e152eaec771121ce0db9f7039f8 (diff) | |
download | scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.tar.gz scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.tar.bz2 scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.zip |
deprecates macro def return type inference
With the new focus on quasiquotes in macro implementations, we now have
to change the way how inference of macro def return types works.
Previously, if the return type of a macro def wasn’t specified, we looked into
the signature of its macro impl, took its return type (which could only
be c.Expr[T]) and then assigned T to be the return type of the macro def.
We also had a convenient special case which inferred Any in case when
the body of the macro impl wasn’t an expr. That avoided reporting spurious
errors if the macro impl had its body typed incorrectly (because in that
case we would report a def/impl signature mismatch anyway) and also provided
a convenience by letting macro impls end with `???`.
However now we also allow macro impls to return c.Tree, which means that
we are no longer able to do any meaningful type inference, because c.Tree
could correspond to tree of any type.
Unfortunately, when coupled with the type inference special case described
above, this means that the users who migrate from exprs to quasiquotes
are going to face an unpleasant surprise. If they haven’t provided
explicit return types for their macro defs, those types are going to be
silently inferred as `Any`!
This commit plugs this loophole by prohibiting type inference from
non-expr return types of macro impls (not counting Nothing). Moreover,
it also deprecates c.Expr[T] => T inference in order to avoid confusion
when switching between exprs and quasiquotes.
Diffstat (limited to 'test/files/run/macro-def-path-dependent')
4 files changed, 28 insertions, 26 deletions
diff --git a/test/files/run/macro-def-path-dependent/Test_1.scala b/test/files/run/macro-def-path-dependent/Test_1.scala index f9aa13c334..bba97fcae1 100644 --- a/test/files/run/macro-def-path-dependent/Test_1.scala +++ b/test/files/run/macro-def-path-dependent/Test_1.scala @@ -1,23 +1,25 @@ -package test1 - -import scala.reflect.macros.{BlackboxContext => Ctx} - -trait Exprs { - self: Universe => - - class Expr[T] -} - -trait Reifiers { - self: Universe => - - type Expr[T] - - def reify[T](expr: T) = macro Impls.reify[T] -} - -trait Universe extends Exprs with Reifiers - -object Impls { - def reify[T](cc: Ctx{ type PrefixType = Reifiers })(expr: cc.Expr[T]): cc.Expr[cc.prefix.value.Expr[T]] = ??? -} +// NOTE: blocked by SI-8049 + +// package test1 +// +// import scala.reflect.macros.{BlackboxContext => Ctx} +// +// trait Exprs { +// self: Universe => +// +// class Expr[T] +// } +// +// trait Reifiers { +// self: Universe => +// +// type Expr[T] +// +// def reify[T](expr: T): Expr[T] = macro Impls.reify[T] +// } +// +// trait Universe extends Exprs with Reifiers +// +// object Impls { +// def reify[T](cc: Ctx{ type PrefixType = Reifiers })(expr: cc.Expr[T]): cc.Expr[cc.prefix.value.Expr[T]] = ??? +// } diff --git a/test/files/run/macro-def-path-dependent/Test_2.scala b/test/files/run/macro-def-path-dependent/Test_2.scala index cdedaf2732..c884ab9d0b 100644 --- a/test/files/run/macro-def-path-dependent/Test_2.scala +++ b/test/files/run/macro-def-path-dependent/Test_2.scala @@ -14,7 +14,7 @@ trait Reifiers { } trait Universe extends Exprs with Reifiers { - def reify[T](expr: T) = macro Impls.reify[T] + def reify[T](expr: T): Expr[T] = macro Impls.reify[T] } object Impls { diff --git a/test/files/run/macro-def-path-dependent/Test_4.scala b/test/files/run/macro-def-path-dependent/Test_4.scala index e8a8cf3909..6562802013 100644 --- a/test/files/run/macro-def-path-dependent/Test_4.scala +++ b/test/files/run/macro-def-path-dependent/Test_4.scala @@ -5,7 +5,7 @@ import scala.reflect.macros.BlackboxContext import scala.reflect.api.Universe object Test { - def materializeTypeTag[T](u: Universe)(e: T) = macro materializeTypeTag_impl[T] + def materializeTypeTag[T](u: Universe)(e: T): u.TypeTag[T] = macro materializeTypeTag_impl[T] def materializeTypeTag_impl[T: c.WeakTypeTag](c: BlackboxContext)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ??? }
\ No newline at end of file diff --git a/test/files/run/macro-def-path-dependent/Test_6.scala b/test/files/run/macro-def-path-dependent/Test_6.scala index c8ddffc143..011e726b3f 100644 --- a/test/files/run/macro-def-path-dependent/Test_6.scala +++ b/test/files/run/macro-def-path-dependent/Test_6.scala @@ -5,5 +5,5 @@ import scala.reflect.macros.BlackboxContext import scala.reflect.api.Universe object Macros { - def materializeTypeTag[T](u: Universe)(e: T) = macro Impls.materializeTypeTag_impl[T] + def materializeTypeTag[T](u: Universe)(e: T): u.TypeTag[T] = macro Impls.materializeTypeTag_impl[T] }
\ No newline at end of file |