diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 3877c36cdb59..bb49c20982b6 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -45,7 +45,7 @@ object Splicer { * - Other parameters are lifted to quoted.Types.TreeExpr (may reference a binding) */ private def getLiftedArgs(call: Tree, bindings: List[Tree])(implicit ctx: Context): List[Any] = { - val bindMap = bindings.map { + val bindMap = bindings.collect { case vdef: ValDef => (vdef.rhs, ref(vdef.symbol)) }.toMap def allArgs(call: Tree, acc: List[List[Tree]]): List[List[Tree]] = call match { diff --git a/tests/run/quote-impure-by-name.check b/tests/run/quote-impure-by-name.check new file mode 100644 index 000000000000..76c0cd1704c7 --- /dev/null +++ b/tests/run/quote-impure-by-name.check @@ -0,0 +1 @@ +1 + {Index.zero[String("bar"), scala.Tuple2[String("baz"), scala.Unit]]} diff --git a/tests/run/quote-impure-by-name/quoted_1.scala b/tests/run/quote-impure-by-name/quoted_1.scala new file mode 100644 index 000000000000..5b83d7c37d93 --- /dev/null +++ b/tests/run/quote-impure-by-name/quoted_1.scala @@ -0,0 +1,18 @@ +import scala.quoted._ + +import dotty.tools.dotc.quoted.Toolbox._ + +class Index[K, Keys](val index: String) extends AnyVal { + override def toString: String = index +} +object Index { + + implicit def zero[K, T]: Index[K, (K, T)] = new Index("0") + + implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ~succImpl('(prev))('[K], '[H], '[T]) + + def succImpl[K, H, T](prev: Expr[Index[K, T]])(implicit k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { + val value = s"1 + {${prev.show}}" + '(new Index(~value.toExpr)) + } +} \ No newline at end of file diff --git a/tests/run/quote-impure-by-name/quoted_2.scala b/tests/run/quote-impure-by-name/quoted_2.scala new file mode 100644 index 000000000000..f0aa41b02962 --- /dev/null +++ b/tests/run/quote-impure-by-name/quoted_2.scala @@ -0,0 +1,6 @@ +object Test { + + def main(args: Array[String]): Unit = { + println(Index.succ["bar", "foo", ("bar", ("baz", Unit))]) + } +} diff --git a/tests/run/quote-indexed-map-by-name/quoted_1.scala b/tests/run/quote-indexed-map-by-name/quoted_1.scala new file mode 100644 index 000000000000..32ed34bac0e6 --- /dev/null +++ b/tests/run/quote-indexed-map-by-name/quoted_1.scala @@ -0,0 +1,13 @@ +import scala.quoted._ + +class Index[K, Keys](val index: Int) extends AnyVal +object Index { + + implicit def zero[K, T]: Index[K, (K, T)] = new Index(0) + + implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ~succImpl('[K], '[H], '[T]) + + def succImpl[K, H, T](implicit k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { + '(new Index(0)) + } +} \ No newline at end of file diff --git a/tests/run/quote-indexed-map-by-name/quoted_2.scala b/tests/run/quote-indexed-map-by-name/quoted_2.scala new file mode 100644 index 000000000000..32b08bea6cc6 --- /dev/null +++ b/tests/run/quote-indexed-map-by-name/quoted_2.scala @@ -0,0 +1,6 @@ +object Test { + + def main(args: Array[String]): Unit = { + Index.succ["bar", "foo", ("bar", ("baz", Unit))] + } +}