summaryrefslogtreecommitdiff
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-01-09 08:10:48 +0100
commitfe6028476931b031e712c37d3e570125b1d034ae (patch)
tree54a47af764aa7ead11041a5488485c24818cf607
parent30e2e3a78f9061ea93352427cb0ca205203041f0 (diff)
downloadscala-fe6028476931b031e712c37d3e570125b1d034ae.tar.gz
scala-fe6028476931b031e712c37d3e570125b1d034ae.tar.bz2
scala-fe6028476931b031e712c37d3e570125b1d034ae.zip
SI-5923 adapt macros when they are deferred
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. 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. 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!
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--test/files/neg/t5353.check2
-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
11 files changed, 6 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index efe7519d5e..c8b7fcee8f 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -77,11 +77,7 @@ abstract class Pickler extends SubComponent {
}
if (!t.isDef && t.hasSymbolField && t.symbol.isTermMacro) {
- unit.error(t.pos, t.symbol.typeParams.length match {
- case 0 => "macro has not been expanded"
- case 1 => "this type parameter must be specified"
- case _ => "these type parameters must be specified"
- })
+ unit.error(t.pos, "macro has not been expanded")
return
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a9e2d479db..b0b1341a07 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1061,6 +1061,7 @@ trait Typers extends Modes with Adaptations with Tags {
instantiateToMethodType(mt)
case _ =>
+ def vanillaAdapt(tree: Tree) = {
def shouldInsertApply(tree: Tree) = inAllModes(mode, EXPRmode | FUNmode) && (tree.tpe match {
case _: MethodType | _: OverloadedType | _: PolyType => false
case _ => applyPossible
@@ -1076,8 +1077,6 @@ trait Typers extends Modes with Adaptations with Tags {
}
if (tree.isType)
adaptType()
- else if (inExprModeButNot(mode, FUNmode) && treeInfo.isMacroApplication(tree))
- macroExpandApply(this, tree, mode, pt)
else if (inAllModes(mode, PATTERNmode | FUNmode))
adaptConstrPattern()
else if (shouldInsertApply(tree))
@@ -1206,6 +1205,9 @@ trait Typers extends Modes with Adaptations with Tags {
}
fallBack
}
+ }
+ val tree1 = if (inExprModeButNot(mode, FUNmode) && treeInfo.isMacroApplication(tree)) macroExpandApply(this, tree, mode, pt) else tree
+ if (tree == tree1) vanillaAdapt(tree1) else tree1
}
}
diff --git a/test/files/neg/t5353.check b/test/files/neg/t5353.check
index 75e2435600..bc3f77a4d6 100644
--- a/test/files/neg/t5353.check
+++ b/test/files/neg/t5353.check
@@ -1,4 +1,4 @@
-t5353.scala:2: error: this type parameter must be specified
+t5353.scala:2: error: macro has not been expanded
def f(x: Boolean) = if (x) Array("abc") else Array()
^
one error found
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