Skip to content

Fix #7110: Remove splices from types involeved in member selection #7176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/pos-macros/i7110/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions tests/pos-macros/i7110/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
16 changes: 16 additions & 0 deletions tests/pos-macros/i7110b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions tests/pos-macros/i7110b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 14 additions & 0 deletions tests/pos-macros/i7110c/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions tests/pos-macros/i7110c/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions tests/pos-macros/i7110d/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions tests/pos-macros/i7110d/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions tests/pos-macros/i7110e/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions tests/pos-macros/i7110e/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
15 changes: 15 additions & 0 deletions tests/pos-macros/i7110f/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions tests/pos-macros/i7110f/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
20 changes: 10 additions & 10 deletions tests/run-staging/quote-type-tags.check
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 4 additions & 2 deletions tests/run-staging/quote-unrolled-foreach.check
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand All @@ -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)
}
})
Expand Down