summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-07-14 02:58:29 +0200
committerEugene Burmako <xeno.by@gmail.com>2013-07-14 02:58:29 +0200
commitef979c02da887b7c56bc1da9c4eb888e92af570f (patch)
tree2e105d3a0c3374875bede127dd6afaf7a1c88715 /test/files/neg
parent2247593472031fd9712b652bab0b978a788e46ef (diff)
downloadscala-ef979c02da887b7c56bc1da9c4eb888e92af570f.tar.gz
scala-ef979c02da887b7c56bc1da9c4eb888e92af570f.tar.bz2
scala-ef979c02da887b7c56bc1da9c4eb888e92af570f.zip
SI-7657 clarifies the "macro overrides method" rule
Currently we allow macros to override non-abstract methods (in order to provide performance enhancements such as foreach for collections), and we also disallow macros to override abstract methods (otherwise downcasting might lead to AbstractMethodErrors). This patch fixes an oversight in the disallowing rule that prohibited macros from overriding a concrete method if that concrete method itself overrides an abstract method. RefCheck entertains all overriding pairs, not only the immediate ones, so the disallowing rule was triggered. Now macros can override abstract methods if and only if either the base type or the self type contain a matching non-abstract method.
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/macro-override-macro-overrides-abstract-method-b.check16
-rw-r--r--test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala17
-rw-r--r--test/files/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala6
3 files changed, 21 insertions, 18 deletions
diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-b.check b/test/files/neg/macro-override-macro-overrides-abstract-method-b.check
index 895e0dca50..cde3dbdbe8 100644
--- a/test/files/neg/macro-override-macro-overrides-abstract-method-b.check
+++ b/test/files/neg/macro-override-macro-overrides-abstract-method-b.check
@@ -1,5 +1,11 @@
-Impls_Macros_1.scala:12: error: overriding method foo in trait Foo of type (x: Int)Int;
- macro method foo cannot override an abstract method
- def foo(x: Int) = macro Impls.impl
- ^
-one error found
+Test_2.scala:3: error: anonymous class $anon inherits conflicting members:
+ macro method t in trait C of type ()Unit and
+ method t in trait A of type ()Unit
+(Note: this can be resolved by declaring an override in anonymous class $anon.)
+ val c2 = new C with A {}
+ ^
+Test_2.scala:5: error: overriding macro method t in trait C of type ()Unit;
+ method t cannot override a macro
+ val c4 = new C with A { override def t(): Unit = () }
+ ^
+two errors found
diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala
index e43264f52f..f5b2555aa5 100644
--- a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala
+++ b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala
@@ -1,13 +1,8 @@
-import scala.reflect.macros.{Context => Ctx}
+import scala.reflect.macros.Context
+import language.experimental.macros
-object Impls {
- def impl(c: Ctx)(x: c.Expr[Int]) = x
-}
+trait T { def t(): Unit }
+trait A { def t(): Unit = () }
-trait Foo {
- def foo(x: Int): Int
-}
-
-object Macros extends Foo {
- def foo(x: Int) = macro Impls.impl
-}
+object Macro { def t(c: Context)(): c.Expr[Unit] = c.universe.reify(()) }
+trait C extends T { self: A => override def t(): Unit = macro Macro.t }
diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala
index 08fff30baf..9b4c8e35f0 100644
--- a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala
+++ b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala
@@ -1,4 +1,6 @@
object Test extends App {
- val designator: Foo = Macros
- designator.foo(42)
+ val c1 = new A with C {}
+ val c2 = new C with A {}
+ val c3 = new C with A { override def t(): Unit = macro Macro.t }
+ val c4 = new C with A { override def t(): Unit = () }
} \ No newline at end of file