Skip to content

Commit 5502daa

Browse files
committed
Fix #7110: Remove splices from types involeved in member selection
1 parent 175d670 commit 5502daa

File tree

15 files changed

+211
-12
lines changed

15 files changed

+211
-12
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,25 @@ class ReifyQuotes extends MacroTransform {
415415
}
416416
tree.symbol.annotations = newAnnotations
417417
super.transform(tree)
418+
419+
case tree @ Select(qual @ Spliced(_), name) if tree.isTerm =>
420+
val qual0 = transform(qual)
421+
//
422+
lazy val erasedSplicesType = new TypeMap() {
423+
override def apply(tp: Type): Type = tp match {
424+
case tp: TypeRef if tp.typeSymbol.isSplice => tp.dealias.typeSymbol.info.hiBound
425+
case tp => mapOver(tp)
426+
}
427+
}.apply(qual.tpe)
428+
429+
val qual1 =
430+
if
431+
tree.symbol.owner.is(Final) && !qual.tpe.member(name).isOverloaded || // Will never be overloaded
432+
qual.tpe =:= erasedSplicesType
433+
then qual0
434+
else Typed(qual0, TypeTree(erasedSplicesType))
435+
436+
cpy.Select(tree)(qual1, name)
418437
case _ =>
419438
super.transform(tree)
420439
}

tests/pos-macros/i7110/Macro_1.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) }
6+
7+
def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{
8+
$sym.Meth(42)
9+
}
10+
}
11+
12+
trait Symantics[R] {
13+
def Meth(exp: Int): R
14+
def Meth(): R
15+
}

tests/pos-macros/i7110/Test_2.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics[Int] {
8+
def Meth(exp: Int): Int = exp
9+
def Meth(): Int = 42
10+
}
11+
12+
val test = m[Int](sym)
13+
}
14+
}

tests/pos-macros/i7110b/Macro_1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m[T](sym: Symantics {type R = T}) : T = ${ mImpl[T]('{sym}) }
6+
7+
def mImpl[T: Type](sym: Expr[Symantics { type R = T }]) given (qctx: QuoteContext): Expr[T] = '{
8+
$sym.Meth(42)
9+
}
10+
}
11+
12+
trait Symantics {
13+
type R
14+
def Meth(exp: Int): R
15+
def Meth(): R
16+
}

tests/pos-macros/i7110b/Test_2.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics {
8+
type R = Int
9+
def Meth(exp: Int): Int = exp
10+
def Meth(): Int = 42
11+
}
12+
13+
val test = m(sym)
14+
}
15+
}

tests/pos-macros/i7110c/Macro_1.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) }
6+
7+
def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{
8+
$sym.Meth(42)
9+
}
10+
}
11+
12+
trait Symantics[R] {
13+
def Meth(exp: Int): R
14+
}

tests/pos-macros/i7110c/Test_2.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics2
8+
9+
val test = m[Int](sym)
10+
}
11+
}
12+
13+
class Symantics2 extends Symantics[Int] {
14+
def Meth(exp: Int): Int = exp
15+
def Meth(): Int = 42
16+
}

tests/pos-macros/i7110d/Macro_1.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m(sym: Symantics) : Int = ${ mImpl('sym) }
6+
7+
def mImpl(sym: Expr[Symantics]) given (qctx: QuoteContext): Expr[Int] = '{
8+
$sym.Meth(42)
9+
}
10+
}
11+
12+
trait Symantics {
13+
def Meth(exp: Int): Int
14+
}

tests/pos-macros/i7110d/Test_2.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics2
8+
9+
val test = m(sym)
10+
}
11+
}
12+
13+
class Symantics2 extends Symantics {
14+
def Meth(exp: Int): Int = exp
15+
def Meth(): Int = 42
16+
}

tests/pos-macros/i7110e/Macro_1.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m(sym: Symantics, x: Int) : Int = ${ mImpl('sym, 'x) }
6+
7+
def mImpl(sym: Expr[Symantics], x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = '{
8+
$sym.Meth($x)
9+
}
10+
}
11+
12+
trait Symantics {
13+
def Meth[R](exp: R): Int
14+
def Meth(): Int
15+
}

tests/pos-macros/i7110e/Test_2.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics {
8+
def Meth[R](exp: R): Int = 2
9+
def Meth(): Int = 42
10+
}
11+
12+
val test = m(sym, 3)
13+
}
14+
}

tests/pos-macros/i7110f/Macro_1.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
5+
inline def m[R](sym: Symantics[R]) : R = ${ mImpl[R]('{sym}) }
6+
7+
def mImpl[R: Type](sym: Expr[Symantics[R]]) given (qctx: QuoteContext): Expr[R] = '{
8+
$sym.Meth(42)
9+
}
10+
}
11+
12+
trait Symantics[R] {
13+
def Meth(exp: Int): R
14+
def Meth(): R
15+
}

tests/pos-macros/i7110f/Test_2.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
import Macros._
3+
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
7+
val sym = new Symantics[Int] {
8+
def Meth(exp: Int): Int = exp
9+
def Meth(): Int = 42
10+
}
11+
12+
val test = m[Int](sym)
13+
}
14+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
().asInstanceOf[scala.Unit]
2-
true.asInstanceOf[scala.Boolean]
3-
0.toByte.asInstanceOf[scala.Byte]
4-
'a'.asInstanceOf[scala.Char]
5-
1.toShort.asInstanceOf[scala.Short]
6-
2.asInstanceOf[scala.Int]
7-
3L.asInstanceOf[scala.Long]
8-
4.0f.asInstanceOf[scala.Float]
9-
5.0.asInstanceOf[scala.Double]
10-
5.0.asInstanceOf[scala.Boolean]
1+
((): scala.Any).asInstanceOf[scala.Unit]
2+
(true: scala.Any).asInstanceOf[scala.Boolean]
3+
(0.toByte: scala.Any).asInstanceOf[scala.Byte]
4+
('a': scala.Any).asInstanceOf[scala.Char]
5+
(1.toShort: scala.Any).asInstanceOf[scala.Short]
6+
(2: scala.Any).asInstanceOf[scala.Int]
7+
(3L: scala.Any).asInstanceOf[scala.Long]
8+
(4.0f: scala.Any).asInstanceOf[scala.Float]
9+
(5.0: scala.Any).asInstanceOf[scala.Double]
10+
(5.0: scala.Any).asInstanceOf[scala.Boolean]

tests/run-staging/quote-unrolled-foreach.check

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
var i: scala.Int = 0
1414
while (i.<(size)) {
1515
val element: java.lang.String = arr.apply(i)
16-
f.apply(element)
16+
17+
(f: scala.Function1[scala.Any, scala.Unit]).apply(element)
1718
i = i.+(1)
1819
}
1920
})
@@ -23,7 +24,8 @@
2324
var i: scala.Int = 0
2425
while (i.<(size)) {
2526
val element: java.lang.String = arr.apply(i)
26-
f.apply(element)
27+
28+
(f: scala.Function1[scala.Any, scala.Unit]).apply(element)
2729
i = i.+(1)
2830
}
2931
})

0 commit comments

Comments
 (0)