summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-10-19 20:10:09 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-10-19 20:44:10 +0200
commit6d4f43503f718610182d9529695d7aed02333e37 (patch)
tree13aec2d83cbaf4f5bc5d155a80c0c24a7011018e
parent8848f241616627b0c5beca38a5107c4eca3e10fd (diff)
downloadscala-6d4f43503f718610182d9529695d7aed02333e37.tar.gz
scala-6d4f43503f718610182d9529695d7aed02333e37.tar.bz2
scala-6d4f43503f718610182d9529695d7aed02333e37.zip
SI-6840 fixes weird typing of quasiquote arguments
Previously quasiquote arguments were type checked against Any which caused weird inference that made splicing of complex expressions unusable: val l1 = List(q"foo") val l2 = List(q"bar") q"f(..${l1 ++ l2})" // argument type checked as Any instead of List[Tree] This is fixed by forcing compiler to type check against type variable which itself isn't used in any other way.
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala2
-rw-r--r--src/reflect/scala/reflect/api/Quasiquotes.scala2
-rw-r--r--test/files/scalacheck/quasiquotes/TermConstructionProps.scala9
3 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala b/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
index 9e98dcbc8b..f4d6b39d02 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
@@ -15,7 +15,7 @@ abstract class Quasiquotes extends Parsers
if (settings.Yquasiquotedebug.value) println(msg)
lazy val (universe: Tree, args, parts, parse, reify, method) = c.macroApplication match {
- case Apply(Select(Select(Apply(Select(universe0, _), List(Apply(_, parts0))), interpolator0), method0), args0) =>
+ case Apply(build.SyntacticTypeApplied(Select(Select(Apply(Select(universe0, _), List(Apply(_, parts0))), interpolator0), method0), _), args0) =>
debug(s"\nparse prefix:\nuniverse=$universe0\nparts=$parts0\ninterpolator=$interpolator0\nmethod=$method0\nargs=$args0\n")
val parts1 = parts0.map {
case lit @ Literal(Constant(s: String)) => s -> lit.pos
diff --git a/src/reflect/scala/reflect/api/Quasiquotes.scala b/src/reflect/scala/reflect/api/Quasiquotes.scala
index 8e993af382..3687ccba63 100644
--- a/src/reflect/scala/reflect/api/Quasiquotes.scala
+++ b/src/reflect/scala/reflect/api/Quasiquotes.scala
@@ -7,7 +7,7 @@ trait Quasiquotes { self: Universe =>
// using the mechanism implemented in `scala.tools.reflect.FastTrack`
implicit class Quasiquote(ctx: StringContext) {
protected trait api {
- def apply(args: Any*): Any = macro ???
+ def apply[T](args: T*): Any = macro ???
def unapply(scrutinee: Any): Any = macro ???
}
object q extends api
diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
index 9284903623..f68656d0f7 100644
--- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
@@ -199,4 +199,13 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") {
def withEvidence = q"def foo[T: X]"
assert(!(withEvidence ≈ withEvidence))
}
+
+ property("make sure inference doesn't infer any") = test {
+ val l1 = List(q"foo")
+ val l2 = List(q"bar")
+ val baz = q"baz"
+ assert(q"f(..${l1 ++ l2})" ≈ q"f(foo, bar)")
+ assert(q"f(..${l1 ++ l2}, $baz)" ≈ q"f(foo, bar, baz)")
+ assert(q"f(${if (true) q"a" else q"b"})" ≈ q"f(a)")
+ }
}