From a667a4bf1f6ab6d28463f0cce8ebd8726d33b406 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 9 Jul 2018 10:40:14 +0200 Subject: [PATCH] Disallow inferred splices and set the correct position --- .../src/dotty/tools/dotc/transform/ReifyQuotes.scala | 3 +-- tests/neg/i4774a.scala | 11 +++++++++++ tests/pos/i4774c.scala | 6 ++++++ tests/pos/{i4774.scala => i4774d.scala} | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/neg/i4774a.scala create mode 100644 tests/pos/i4774c.scala rename tests/pos/{i4774.scala => i4774d.scala} (72%) diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 156891cc2357..7999c1c7d149 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -568,8 +568,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer { quotation(quotedTree, tree) case tree: TypeTree if tree.tpe.typeSymbol.isSplice => val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol - if (levelOf.get(splicedType).contains(level)) tree - else splice(ref(splicedType).select(tpnme.UNARY_~)) + splice(ref(splicedType).select(tpnme.UNARY_~).withPos(tree.pos)) case tree: Select if tree.symbol.isSplice => splice(tree) case tree: RefTree if isCaptured(tree.symbol, level) => diff --git a/tests/neg/i4774a.scala b/tests/neg/i4774a.scala new file mode 100644 index 000000000000..1c9fff1ef65f --- /dev/null +++ b/tests/neg/i4774a.scala @@ -0,0 +1,11 @@ + +import scala.quoted._ + +object Test { + def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ + val y: ~t = ~x + ~loop( // error: inferred loop[~t] where T should be used + '(y) + ) + } +} diff --git a/tests/pos/i4774c.scala b/tests/pos/i4774c.scala new file mode 100644 index 000000000000..8282616259d3 --- /dev/null +++ b/tests/pos/i4774c.scala @@ -0,0 +1,6 @@ + +import scala.quoted._ + +object Test { + def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ val y = ~x; ~loop('(y)) } +} diff --git a/tests/pos/i4774.scala b/tests/pos/i4774d.scala similarity index 72% rename from tests/pos/i4774.scala rename to tests/pos/i4774d.scala index 1e17e5c953ab..2a17e34b4f8f 100644 --- a/tests/pos/i4774.scala +++ b/tests/pos/i4774d.scala @@ -3,5 +3,5 @@ import scala.quoted._ object Test { def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = - '{ val y: ~t = ~x; ~loop('(y)) } + '{ val y: T = ~x; ~loop('(y)) } }