summaryrefslogtreecommitdiff
path: root/test/files/pos/t8934a
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-10-23 16:26:46 +1000
committerJason Zaugg <jzaugg@gmail.com>2014-10-27 22:34:33 +1000
commit337b52b298be95df0b4b9a4bacb7c4b802620cf6 (patch)
treeb9e211946e905a455082bf56dbd8095a5515b7ff /test/files/pos/t8934a
parent850899b1c9347e804763a258f64d54cef0ffd69a (diff)
downloadscala-337b52b298be95df0b4b9a4bacb7c4b802620cf6.tar.gz
scala-337b52b298be95df0b4b9a4bacb7c4b802620cf6.tar.bz2
scala-337b52b298be95df0b4b9a4bacb7c4b802620cf6.zip
SI-8934 Fix whitebox extractor macros in the pres. compiler
The code that "aligns" patterns and extractors assumes that it can look at the type of the unapply method to figure the arity of the extractor. However, the result type of a whitebox macro does not tell the whole story, only after expanding an application of that macro do we know the result type. During regular compilation, this isn't a problem, as the macro application is expanded to a call to a synthetic unapply: { class anon$1 { def unapply(tree: Any): Option[(Tree, List[Treed])] } new anon$1 }.unapply(<unapply selector>) In the presentation compiler, however, we now use `-Ymacro-expand:discard`, which expands macros only to compute the type of the application (and to allow the macro to issue warnings/errors). The original application is retained in the typechecked tree, modified only by attributing the potentially-sharper type taken from the expanded macro. This was done to improve hyperlinking support in the IDE. This commit passes `sel.tpe` (which is the type computed by the macro expansion) to `unapplyMethodTypes`, rather than using the `finalResultType` of the unapply method. This is tested with a presentation compiler test (which closely mimics the reported bug), and with a pos test that also exercises `-Ymacro-expand:discard`. Prior to this patch, they used to fail with: too many patterns for trait api: expected 1, found 2
Diffstat (limited to 'test/files/pos/t8934a')
-rw-r--r--test/files/pos/t8934a/A_1.scala18
-rw-r--r--test/files/pos/t8934a/Test_2.flags1
-rw-r--r--test/files/pos/t8934a/Test_2.scala12
3 files changed, 31 insertions, 0 deletions
diff --git a/test/files/pos/t8934a/A_1.scala b/test/files/pos/t8934a/A_1.scala
new file mode 100644
index 0000000000..6c1f29d030
--- /dev/null
+++ b/test/files/pos/t8934a/A_1.scala
@@ -0,0 +1,18 @@
+import language.experimental.macros
+import reflect.macros.whitebox.Context
+
+object Unapply {
+ def impl1(c: Context)(a: c.Tree): c.Tree = {
+ import c.universe._
+ q"(new { def unapply[T](a: String): Option[(Int, String)] = ??? }).unapply($a)"
+ }
+ def unapply(a: Any): Any = macro impl1
+}
+
+object UnapplySeq {
+ def impl1(c: Context)(a: c.Tree): c.Tree = {
+ import c.universe._
+ q"(new { def unapplySeq[T](a: String): Option[(Int, Seq[String])] = ??? }).unapplySeq($a)"
+ }
+ def unapplySeq(a: Any): Any = macro impl1
+}
diff --git a/test/files/pos/t8934a/Test_2.flags b/test/files/pos/t8934a/Test_2.flags
new file mode 100644
index 0000000000..618dfe2b75
--- /dev/null
+++ b/test/files/pos/t8934a/Test_2.flags
@@ -0,0 +1 @@
+-Ystop-after:typer -Ymacro-expand:discard -nowarn
diff --git a/test/files/pos/t8934a/Test_2.scala b/test/files/pos/t8934a/Test_2.scala
new file mode 100644
index 0000000000..e1792ed3c5
--- /dev/null
+++ b/test/files/pos/t8934a/Test_2.scala
@@ -0,0 +1,12 @@
+object Test {
+ "" match {
+ case Unapply(a, b) =>
+ a: Int
+ b: String
+ case UnapplySeq(a, b1, b2) =>
+ a: Int
+ b1: String
+ b2: String
+ }
+}
+// These used to fail `too many patterns` under -Ymacro-expand:discard