From f51c3f8b98f34dc97abb591f011030124751683c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sat, 7 Jul 2018 13:01:22 +0200 Subject: [PATCH] Fix #4774: Skip TypeVars and skip if level is equal If we have ~t for `t: Type[T]` used at the same level it is an alias for T. We disallow it if it is explicit because of PCP but if it is infered it is fine. --- .../src/dotty/tools/dotc/transform/ReifyQuotes.scala | 5 +++-- tests/neg/i4774b.scala | 11 +++++++++++ tests/pos/i4774.scala | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i4774b.scala create mode 100644 tests/pos/i4774.scala diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 9cc37d3716bd..156891cc2357 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -567,8 +567,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer { case Quoted(quotedTree) => quotation(quotedTree, tree) case tree: TypeTree if tree.tpe.typeSymbol.isSplice => - val splicedType = tree.tpe.asInstanceOf[TypeRef].prefix.termSymbol - splice(ref(splicedType).select(tpnme.UNARY_~)) + val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol + if (levelOf.get(splicedType).contains(level)) tree + else splice(ref(splicedType).select(tpnme.UNARY_~)) case tree: Select if tree.symbol.isSplice => splice(tree) case tree: RefTree if isCaptured(tree.symbol, level) => diff --git a/tests/neg/i4774b.scala b/tests/neg/i4774b.scala new file mode 100644 index 000000000000..517aa02f9823 --- /dev/null +++ b/tests/neg/i4774b.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[~t]( // error + '(y) + ) + } +} diff --git a/tests/pos/i4774.scala b/tests/pos/i4774.scala new file mode 100644 index 000000000000..1e17e5c953ab --- /dev/null +++ b/tests/pos/i4774.scala @@ -0,0 +1,7 @@ + +import scala.quoted._ + +object Test { + def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + '{ val y: ~t = ~x; ~loop('(y)) } +}