summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-12-31 15:46:47 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-05-11 18:37:10 +0200
commit90ac5c4e1350493f6f47c674572c2dcb97b2b9eb (patch)
treedc944493949cdb17bf2aa032b62c117f29054fc1 /test
parent0c6927b4845633f262794aadda9b188b140717b6 (diff)
downloadscala-90ac5c4e1350493f6f47c674572c2dcb97b2b9eb.tar.gz
scala-90ac5c4e1350493f6f47c674572c2dcb97b2b9eb.tar.bz2
scala-90ac5c4e1350493f6f47c674572c2dcb97b2b9eb.zip
[nomaster] SI-5923 instantiates targs in deferred macro applications
Amazingly enough, the fix for the "macro not expanded" problem was super easy. (And I remember spending a day or two trying to find a quick fix somewhen around Scala Days 2012!) The problem was in the implementation of the macro expansion trigger, which was buried in a chain of if-elif-elif in `adapt`. This meant that macro expansion was mutually exclusive with a lot of important adaptations, e.g. with `instantiate`. More precisely, if an expandee contains an undetparam, its expansion should be delayed until all its undetparams are inferred and then retried later. Sometimes such inference can only happen upon a call to instantiate in one of the elif's coming after the macro expansion elif. However this elif would never be called for expandees, because control flow would always enter the macro expansion branch preceding the inference branch. Therefore `macroExpand` now takes the matters in its own hands, calling `instantiate` if the expansion has been delayed and we're not in POLYmode (see a detailed explanation in a comment to `macroExpand`). Consequences of this fix are vast. First of all, we can get rid of the "type parameter must be specified" hack. Secondly and most importantly, we can now remove the `materializeImplicit` method from Implicits and rely on implicit macros to materialize tags for us. (This is a tricky change, and I'll do it later after we merge as much of my pending work as possible). Finally, we learn that the current scheme of interaction between macros, type inference and implicits is, in principle, sound! NOTE: This patch is a second take on fixing implicit macros, with the first one being a backport from macro paradise merged into master in January 2013: https://github.com/scala/scala/commit/fe60284769. The original fix had an unfortunate error, as described on scala-internals: https://groups.google.com/forum/#!msg/scala-internals/7pA9CiiD3u8, so I had to refine the approach here. This means that it's not possible to directly merge this commit into master, so I'm marking it as [nomaster] and will submit a separate pull request targetting master later on.
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/t5692a.check (renamed from test/files/neg/t5692a.check)0
-rw-r--r--test/files/pos/t5692a.flags (renamed from test/files/neg/t5692a.flags)0
-rw-r--r--test/files/pos/t5692a/Macros_1.scala (renamed from test/files/neg/t5692a/Macros_1.scala)0
-rw-r--r--test/files/pos/t5692a/Test_2.scala (renamed from test/files/neg/t5692a/Test_2.scala)0
-rw-r--r--test/files/pos/t5692b.check (renamed from test/files/neg/t5692b.check)0
-rw-r--r--test/files/pos/t5692b.flags (renamed from test/files/neg/t5692b.flags)0
-rw-r--r--test/files/pos/t5692b/Macros_1.scala (renamed from test/files/neg/t5692b/Macros_1.scala)0
-rw-r--r--test/files/pos/t5692b/Test_2.scala (renamed from test/files/neg/t5692b/Test_2.scala)0
-rw-r--r--test/files/run/t5923a.check3
-rw-r--r--test/files/run/t5923a/Macros_1.scala14
-rw-r--r--test/files/run/t5923a/Test_2.scala5
-rw-r--r--test/files/run/t5923b.check3
-rw-r--r--test/files/run/t5923b/Test.scala7
13 files changed, 32 insertions, 0 deletions
diff --git a/test/files/neg/t5692a.check b/test/files/pos/t5692a.check
index 7fbfb5dba7..7fbfb5dba7 100644
--- a/test/files/neg/t5692a.check
+++ b/test/files/pos/t5692a.check
diff --git a/test/files/neg/t5692a.flags b/test/files/pos/t5692a.flags
index cd66464f2f..cd66464f2f 100644
--- a/test/files/neg/t5692a.flags
+++ b/test/files/pos/t5692a.flags
diff --git a/test/files/neg/t5692a/Macros_1.scala b/test/files/pos/t5692a/Macros_1.scala
index 06b5a3de36..06b5a3de36 100644
--- a/test/files/neg/t5692a/Macros_1.scala
+++ b/test/files/pos/t5692a/Macros_1.scala
diff --git a/test/files/neg/t5692a/Test_2.scala b/test/files/pos/t5692a/Test_2.scala
index 08d510cc6f..08d510cc6f 100644
--- a/test/files/neg/t5692a/Test_2.scala
+++ b/test/files/pos/t5692a/Test_2.scala
diff --git a/test/files/neg/t5692b.check b/test/files/pos/t5692b.check
index 16796826b4..16796826b4 100644
--- a/test/files/neg/t5692b.check
+++ b/test/files/pos/t5692b.check
diff --git a/test/files/neg/t5692b.flags b/test/files/pos/t5692b.flags
index cd66464f2f..cd66464f2f 100644
--- a/test/files/neg/t5692b.flags
+++ b/test/files/pos/t5692b.flags
diff --git a/test/files/neg/t5692b/Macros_1.scala b/test/files/pos/t5692b/Macros_1.scala
index b28d19f903..b28d19f903 100644
--- a/test/files/neg/t5692b/Macros_1.scala
+++ b/test/files/pos/t5692b/Macros_1.scala
diff --git a/test/files/neg/t5692b/Test_2.scala b/test/files/pos/t5692b/Test_2.scala
index 08d510cc6f..08d510cc6f 100644
--- a/test/files/neg/t5692b/Test_2.scala
+++ b/test/files/pos/t5692b/Test_2.scala
diff --git a/test/files/run/t5923a.check b/test/files/run/t5923a.check
new file mode 100644
index 0000000000..7165b734ac
--- /dev/null
+++ b/test/files/run/t5923a.check
@@ -0,0 +1,3 @@
+C(Int)
+C(String)
+C(Nothing)
diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala
new file mode 100644
index 0000000000..6d21362c4d
--- /dev/null
+++ b/test/files/run/t5923a/Macros_1.scala
@@ -0,0 +1,14 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+case class C[T](t: String)
+object C {
+ implicit def foo[T]: C[T] = macro Macros.impl[T]
+}
+
+object Macros {
+ def impl[T: c.WeakTypeTag](c: Context) = {
+ import c.universe._
+ reify(C[T](c.literal(weakTypeOf[T].toString).splice))
+ }
+} \ No newline at end of file
diff --git a/test/files/run/t5923a/Test_2.scala b/test/files/run/t5923a/Test_2.scala
new file mode 100644
index 0000000000..001ff9aea8
--- /dev/null
+++ b/test/files/run/t5923a/Test_2.scala
@@ -0,0 +1,5 @@
+object Test extends App {
+ println(implicitly[C[Int]])
+ println(implicitly[C[String]])
+ println(implicitly[C[Nothing]])
+} \ No newline at end of file
diff --git a/test/files/run/t5923b.check b/test/files/run/t5923b.check
new file mode 100644
index 0000000000..d56076f84e
--- /dev/null
+++ b/test/files/run/t5923b.check
@@ -0,0 +1,3 @@
+class [Ljava.lang.Object;
+class [Ljava.lang.Object;
+class [Ljava.lang.Object;
diff --git a/test/files/run/t5923b/Test.scala b/test/files/run/t5923b/Test.scala
new file mode 100644
index 0000000000..7c2627462a
--- /dev/null
+++ b/test/files/run/t5923b/Test.scala
@@ -0,0 +1,7 @@
+object Test extends App {
+ import scala.collection.generic.CanBuildFrom
+ val cbf = implicitly[CanBuildFrom[Nothing, Nothing, Array[Nothing]]]
+ println(cbf().result.getClass)
+ println(new Array[Nothing](0).getClass)
+ println(Array[Nothing]().getClass)
+} \ No newline at end of file