diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index bd1f48e1a45d..62efe9fe2917 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -415,6 +415,25 @@ class ReifyQuotes extends MacroTransform { } tree.symbol.annotations = newAnnotations super.transform(tree) + + case tree @ Select(qual @ Spliced(_), name) if tree.isTerm => + val qual0 = transform(qual) + // + lazy val erasedSplicesType = new TypeMap() { + override def apply(tp: Type): Type = tp match { + case tp: TypeRef if tp.typeSymbol.isSplice => tp.dealias.typeSymbol.info.hiBound + case tp => mapOver(tp) + } + }.apply(qual.tpe) + + val qual1 = + if + tree.symbol.owner.is(Final) && !qual.tpe.member(name).isOverloaded || // Will never be overloaded + qual.tpe =:= erasedSplicesType + then qual0 + else Typed(qual0, TypeTree(erasedSplicesType)) + + cpy.Select(tree)(qual1, name) case _ => super.transform(tree) } diff --git a/tests/pos-macros/i7110/Macro_1.scala b/tests/pos-macros/i7110/Macro_1.scala new file mode 100644 index 000000000000..428a203b8520 --- /dev/null +++ b/tests/pos-macros/i7110/Macro_1.scala @@ -0,0 +1,15 @@ +import scala.quoted._ + +object Macros { + + inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) } + + def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{ + $sym.Meth(42) + } +} + +trait Symantics[R] { + def Meth(exp: Int): R + def Meth(): R +} diff --git a/tests/pos-macros/i7110/Test_2.scala b/tests/pos-macros/i7110/Test_2.scala new file mode 100644 index 000000000000..c901785a7bf1 --- /dev/null +++ b/tests/pos-macros/i7110/Test_2.scala @@ -0,0 +1,14 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics[Int] { + def Meth(exp: Int): Int = exp + def Meth(): Int = 42 + } + + val test = m[Int](sym) + } +} diff --git a/tests/pos-macros/i7110b/Macro_1.scala b/tests/pos-macros/i7110b/Macro_1.scala new file mode 100644 index 000000000000..d3f877d17002 --- /dev/null +++ b/tests/pos-macros/i7110b/Macro_1.scala @@ -0,0 +1,16 @@ +import scala.quoted._ + +object Macros { + + inline def m[T](sym: Symantics {type R = T}) : T = ${ mImpl[T]('{sym}) } + + def mImpl[T: Type](sym: Expr[Symantics { type R = T }]) given (qctx: QuoteContext): Expr[T] = '{ + $sym.Meth(42) + } +} + +trait Symantics { + type R + def Meth(exp: Int): R + def Meth(): R +} diff --git a/tests/pos-macros/i7110b/Test_2.scala b/tests/pos-macros/i7110b/Test_2.scala new file mode 100644 index 000000000000..b4ee47b71e14 --- /dev/null +++ b/tests/pos-macros/i7110b/Test_2.scala @@ -0,0 +1,15 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics { + type R = Int + def Meth(exp: Int): Int = exp + def Meth(): Int = 42 + } + + val test = m(sym) + } +} diff --git a/tests/pos-macros/i7110c/Macro_1.scala b/tests/pos-macros/i7110c/Macro_1.scala new file mode 100644 index 000000000000..eadb876a1ba1 --- /dev/null +++ b/tests/pos-macros/i7110c/Macro_1.scala @@ -0,0 +1,14 @@ +import scala.quoted._ + +object Macros { + + inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) } + + def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{ + $sym.Meth(42) + } +} + +trait Symantics[R] { + def Meth(exp: Int): R +} diff --git a/tests/pos-macros/i7110c/Test_2.scala b/tests/pos-macros/i7110c/Test_2.scala new file mode 100644 index 000000000000..efb82b88f669 --- /dev/null +++ b/tests/pos-macros/i7110c/Test_2.scala @@ -0,0 +1,16 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics2 + + val test = m[Int](sym) + } +} + +class Symantics2 extends Symantics[Int] { + def Meth(exp: Int): Int = exp + def Meth(): Int = 42 +} \ No newline at end of file diff --git a/tests/pos-macros/i7110d/Macro_1.scala b/tests/pos-macros/i7110d/Macro_1.scala new file mode 100644 index 000000000000..dd15ce50e106 --- /dev/null +++ b/tests/pos-macros/i7110d/Macro_1.scala @@ -0,0 +1,14 @@ +import scala.quoted._ + +object Macros { + + inline def m(sym: Symantics) : Int = ${ mImpl('sym) } + + def mImpl(sym: Expr[Symantics]) given (qctx: QuoteContext): Expr[Int] = '{ + $sym.Meth(42) + } +} + +trait Symantics { + def Meth(exp: Int): Int +} diff --git a/tests/pos-macros/i7110d/Test_2.scala b/tests/pos-macros/i7110d/Test_2.scala new file mode 100644 index 000000000000..5582ec55a133 --- /dev/null +++ b/tests/pos-macros/i7110d/Test_2.scala @@ -0,0 +1,16 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics2 + + val test = m(sym) + } +} + +class Symantics2 extends Symantics { + def Meth(exp: Int): Int = exp + def Meth(): Int = 42 +} diff --git a/tests/pos-macros/i7110e/Macro_1.scala b/tests/pos-macros/i7110e/Macro_1.scala new file mode 100644 index 000000000000..1a9c15a8c3c9 --- /dev/null +++ b/tests/pos-macros/i7110e/Macro_1.scala @@ -0,0 +1,15 @@ +import scala.quoted._ + +object Macros { + + inline def m(sym: Symantics, x: Int) : Int = ${ mImpl('sym, 'x) } + + def mImpl(sym: Expr[Symantics], x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = '{ + $sym.Meth($x) + } +} + +trait Symantics { + def Meth[R](exp: R): Int + def Meth(): Int +} diff --git a/tests/pos-macros/i7110e/Test_2.scala b/tests/pos-macros/i7110e/Test_2.scala new file mode 100644 index 000000000000..881ce247c65c --- /dev/null +++ b/tests/pos-macros/i7110e/Test_2.scala @@ -0,0 +1,14 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics { + def Meth[R](exp: R): Int = 2 + def Meth(): Int = 42 + } + + val test = m(sym, 3) + } +} diff --git a/tests/pos-macros/i7110f/Macro_1.scala b/tests/pos-macros/i7110f/Macro_1.scala new file mode 100644 index 000000000000..428a203b8520 --- /dev/null +++ b/tests/pos-macros/i7110f/Macro_1.scala @@ -0,0 +1,15 @@ +import scala.quoted._ + +object Macros { + + inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) } + + def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{ + $sym.Meth(42) + } +} + +trait Symantics[R] { + def Meth(exp: Int): R + def Meth(): R +} diff --git a/tests/pos-macros/i7110f/Test_2.scala b/tests/pos-macros/i7110f/Test_2.scala new file mode 100644 index 000000000000..c901785a7bf1 --- /dev/null +++ b/tests/pos-macros/i7110f/Test_2.scala @@ -0,0 +1,14 @@ +import scala.quoted._ +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + + val sym = new Symantics[Int] { + def Meth(exp: Int): Int = exp + def Meth(): Int = 42 + } + + val test = m[Int](sym) + } +} diff --git a/tests/run-staging/quote-type-tags.check b/tests/run-staging/quote-type-tags.check index b66fef76fba5..696b0376d8c6 100644 --- a/tests/run-staging/quote-type-tags.check +++ b/tests/run-staging/quote-type-tags.check @@ -1,10 +1,10 @@ -().asInstanceOf[scala.Unit] -true.asInstanceOf[scala.Boolean] -0.toByte.asInstanceOf[scala.Byte] -'a'.asInstanceOf[scala.Char] -1.toShort.asInstanceOf[scala.Short] -2.asInstanceOf[scala.Int] -3L.asInstanceOf[scala.Long] -4.0f.asInstanceOf[scala.Float] -5.0.asInstanceOf[scala.Double] -5.0.asInstanceOf[scala.Boolean] +((): scala.Any).asInstanceOf[scala.Unit] +(true: scala.Any).asInstanceOf[scala.Boolean] +(0.toByte: scala.Any).asInstanceOf[scala.Byte] +('a': scala.Any).asInstanceOf[scala.Char] +(1.toShort: scala.Any).asInstanceOf[scala.Short] +(2: scala.Any).asInstanceOf[scala.Int] +(3L: scala.Any).asInstanceOf[scala.Long] +(4.0f: scala.Any).asInstanceOf[scala.Float] +(5.0: scala.Any).asInstanceOf[scala.Double] +(5.0: scala.Any).asInstanceOf[scala.Boolean] diff --git a/tests/run-staging/quote-unrolled-foreach.check b/tests/run-staging/quote-unrolled-foreach.check index 3e923884848e..0bbdd6d29a7b 100644 --- a/tests/run-staging/quote-unrolled-foreach.check +++ b/tests/run-staging/quote-unrolled-foreach.check @@ -13,7 +13,8 @@ var i: scala.Int = 0 while (i.<(size)) { val element: java.lang.String = arr.apply(i) - f.apply(element) + + (f: scala.Function1[scala.Any, scala.Unit]).apply(element) i = i.+(1) } }) @@ -23,7 +24,8 @@ var i: scala.Int = 0 while (i.<(size)) { val element: java.lang.String = arr.apply(i) - f.apply(element) + + (f: scala.Function1[scala.Any, scala.Unit]).apply(element) i = i.+(1) } })