From 488444b327f222fa4ef317b5d96fb7cdf732d4d2 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 3 Jun 2013 21:51:39 +0200 Subject: cleans up 82f0925 Updates comments, implements accidentally forgotten IMPLPARAM_TREE, creates a test to ensure that nothing else is overseen. --- test/files/run/macro-impl-relaxed.check | 4 ++++ test/files/run/macro-impl-relaxed/Macros_1.scala | 14 ++++++++++++++ test/files/run/macro-impl-relaxed/Test_2.scala | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 test/files/run/macro-impl-relaxed.check create mode 100644 test/files/run/macro-impl-relaxed/Macros_1.scala create mode 100644 test/files/run/macro-impl-relaxed/Test_2.scala (limited to 'test') diff --git a/test/files/run/macro-impl-relaxed.check b/test/files/run/macro-impl-relaxed.check new file mode 100644 index 0000000000..487b116534 --- /dev/null +++ b/test/files/run/macro-impl-relaxed.check @@ -0,0 +1,4 @@ +2 +2 +2 +2 diff --git a/test/files/run/macro-impl-relaxed/Macros_1.scala b/test/files/run/macro-impl-relaxed/Macros_1.scala new file mode 100644 index 0000000000..af62646b4e --- /dev/null +++ b/test/files/run/macro-impl-relaxed/Macros_1.scala @@ -0,0 +1,14 @@ +import language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def implUU(c: Context)(x: c.Tree): c.Tree = x + def implTU(c: Context)(x: c.Expr[Int]): c.Tree = x.tree + def implUT(c: Context)(x: c.Tree): c.Expr[Int] = c.Expr[Int](x) + def implTT(c: Context)(x: c.Expr[Int]): c.Expr[Int] = x + + def fooUU(x: Int): Int = macro implUU + def fooTU(x: Int): Int = macro implTU + def fooUT(x: Int): Int = macro implUT + def fooTT(x: Int): Int = macro implTT +} \ No newline at end of file diff --git a/test/files/run/macro-impl-relaxed/Test_2.scala b/test/files/run/macro-impl-relaxed/Test_2.scala new file mode 100644 index 0000000000..2eaeef0fd0 --- /dev/null +++ b/test/files/run/macro-impl-relaxed/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + println(Macros.fooUU(2)) + println(Macros.fooTU(2)) + println(Macros.fooUT(2)) + println(Macros.fooTT(2)) +} \ No newline at end of file -- cgit v1.2.3 From ee646e9c84290e721c4ee9fe6247d4b95840e871 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 5 Jun 2013 16:51:06 +0200 Subject: fixes a crash on a degenerate macro definition Previous version of the MacroImplReference extractor didn't take into the account the fact that RefTree.qualifier.symbol can be null (and it can be null if RefTree is an Ident, because then qualifier is an EmptyTree). This led to NPEs for really weird macro defs that refer to local methods as their corresponding macro impls. Now I check for this corner case, and the stuff now longer crashes. This was wrong; this is how I fixed it; the world is now a better place. --- src/reflect/scala/reflect/internal/TreeInfo.scala | 7 ++++--- test/files/neg/macro-invalidshape.check | 7 ++++++- test/files/neg/macro-invalidshape/Macros_Test_2.scala | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala index d1e8a04553..3a8d3fd460 100644 --- a/src/reflect/scala/reflect/internal/TreeInfo.scala +++ b/src/reflect/scala/reflect/internal/TreeInfo.scala @@ -837,11 +837,12 @@ abstract class TreeInfo { def unapply(tree: Tree) = refPart(tree) match { case ref: RefTree => { - val isBundle = definitions.isMacroBundleType(ref.qualifier.tpe) + val qual = ref.qualifier + val isBundle = definitions.isMacroBundleType(qual.tpe) val owner = - if (isBundle) ref.qualifier.tpe.typeSymbol + if (isBundle) qual.tpe.typeSymbol else { - val sym = ref.qualifier.symbol + val sym = if (qual.hasSymbolField) qual.symbol else NoSymbol if (sym.isModule) sym.moduleClass else sym } Some((isBundle, owner, ref.symbol, dissectApplied(tree).targs)) diff --git a/test/files/neg/macro-invalidshape.check b/test/files/neg/macro-invalidshape.check index 40a2952569..1938f5ae47 100644 --- a/test/files/neg/macro-invalidshape.check +++ b/test/files/neg/macro-invalidshape.check @@ -12,4 +12,9 @@ Macros_Test_2.scala:4: error: missing arguments for method foo in object Impls; follow this method with `_' if you want to treat it as a partially applied function def foo3(x: Any) = macro {2; Impls.foo} ^ -three errors found +Macros_Test_2.scala:7: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo = macro impl + ^ +four errors found diff --git a/test/files/neg/macro-invalidshape/Macros_Test_2.scala b/test/files/neg/macro-invalidshape/Macros_Test_2.scala index f39ad20c5d..cf37e14d8e 100644 --- a/test/files/neg/macro-invalidshape/Macros_Test_2.scala +++ b/test/files/neg/macro-invalidshape/Macros_Test_2.scala @@ -2,6 +2,11 @@ object Macros { def foo1(x: Any) = macro 2 def foo2(x: Any) = macro Impls.foo(null)(null) def foo3(x: Any) = macro {2; Impls.foo} + { + def impl(c: scala.reflect.macros.Context) = c.literalUnit + def foo = macro impl + foo + } } object Test extends App { -- cgit v1.2.3