Skip to content

Commit bb96180

Browse files
committed
Use canonical underlying type reference
1 parent 19e47b7 commit bb96180

File tree

15 files changed

+34
-32
lines changed

15 files changed

+34
-32
lines changed

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ trait QuotesAndSplices {
180180
else
181181
val tree1 = typedSelect(untpd.Select(tree.expr, tpnme.Underlying), pt)(using spliceContext).withSpan(tree.span)
182182
val msg = em"Consider using canonical type reference ${tree1.tpe} instead"
183-
if sourceVersion.isAtLeast(`3.1-migration`) then report.error(msg, tree.srcPos)
184-
else report.warning(msg, tree.srcPos)
183+
// if sourceVersion.isAtLeast(`3.1-migration`) then
184+
report.error(msg, tree.srcPos)
185+
// else report.warning(msg, tree.srcPos)
185186
tree1
186187
}
187188

tests/neg-macros/i4774b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import scala.quoted._
33

44
object Test {
55
def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{
6-
val y: $t = $x;
7-
${loop[$t]( // error
6+
val y: t.Underlying = $x;
7+
${loop[t.Underlying]( // error
88
'y
99
)}
1010
}

tests/neg-macros/i6997.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import scala.quoted._
33
class Foo {
44
def mcrImpl(body: Expr[Any])(using t: Type[_ <: Any])(using ctx: QuoteContext): Expr[Any] = '{
5-
val tmp = ???.asInstanceOf[$t] // error // error
5+
val tmp = ???.asInstanceOf[t.Underlying] // error // error
66
tmp
77
}
88
}

tests/neg-macros/i7048e.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ abstract class Test {
1616
import t.given
1717
println(summon[Type[t.T]].show)
1818
// val r = '{Option.empty[t.T]} // access to value t from wrong staging level
19-
val r2 = '{Option.empty[${t.T}]} // works
19+
val r2 = '{Option.empty[t.T.Underlying]} // works
2020
}
2121

2222
{
23-
val r1 = '{Option.empty[${T}]} // works
24-
val r2 = '{Option.empty[List[${T}]]} // works
25-
val r3 = '{summon[Type[${T}]]} // error: is not stable
26-
val r4 = '{summon[${T} <:< Any]} // error: is not stable
23+
val r1 = '{Option.empty[T.Underlying]} // works
24+
val r2 = '{Option.empty[List[T.Underlying]]} // works
25+
val r3 = '{summon[Type[T.Underlying]]} // error: is not stable
26+
val r4 = '{summon[T.Underlying <:< Any]} // error: is not stable
2727
}
2828

2929
{
30-
val s = '{Option.empty[${T}]} // works
30+
val s = '{Option.empty[T.Underlying]} // works
3131
val r = '{identity($s)} // works
3232
val r2 = '{identity(${s: Expr[Option[T]]})} // error // error : is not stable
3333
}

tests/pos-macros/i4023c/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import scala.quoted._
22
object Macro {
33
inline def ff[T](x: T): T = ${ impl('x)('[T], summon[QuoteContext]) }
4-
def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: $t }
4+
def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: T }
55
}

tests/pos-macros/i4774a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted._
33

44
object Test {
55
def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{
6-
val y: $t = $x
6+
val y: T = $x
77
${loop('y)}
88
}
99
}

tests/pos-macros/i6210/Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ object Macro {
77
def impl[A : Type, B : Type](using QuoteContext): Expr[Any] = {
88
val t = '[Map[A, B]]
99
'{
10-
new Object().asInstanceOf[$t]
11-
???.asInstanceOf[$t]
10+
new Object().asInstanceOf[t.Underlying]
11+
???.asInstanceOf[t.Underlying]
1212
}
1313
}
1414
}

tests/pos-macros/i7048e.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ abstract class Test {
1616
import t.given
1717
println(summon[Type[t.T]].show)
1818
// val r = '{Option.empty[t.T]} // access to value t from wrong staging level
19-
val r2 = '{Option.empty[${t.T}]}
19+
val r2 = '{Option.empty[t.T.Underlying]}
2020
}
2121

2222
{
23-
val r1 = '{Option.empty[${T}]} // works
24-
val r2 = '{Option.empty[List[${T}]]} // works
25-
// val r3 = '{summon[Type[${T}]]} // access to Test.this from wrong staging level
26-
val r4 = '{summon[${T} <:< Any]}
23+
val r1 = '{Option.empty[T.Underlying]} // works
24+
val r2 = '{Option.empty[List[T.Underlying]]} // works
25+
// val r3 = '{summon[Type[T.Underlying]]} // access to Test.this from wrong staging level
26+
val r4 = '{summon[T.Underlying <:< Any]}
2727
}
2828

2929
{
30-
val s = '{Option.empty[${T}]}
30+
val s = '{Option.empty[T.Underlying]}
3131
val r = '{identity($s)} // works
3232
val r2 = '{identity(${s: Expr[Option[T]]})}
3333
}

tests/pos-macros/i7405.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Foo {
66
val x: X = ???
77
${
88
val t: Type[X] = '[X] // Level 0
9-
'{ val y: $t = x }
9+
'{ val y: t.Underlying = x }
1010
}
1111
}
1212
}

tests/pos-macros/i7405b.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Foo {
1111
type Z = x.Y
1212
${
1313
val t: Type[Z] = '[Z]
14-
'{ val y: $t = x.y }
14+
'{ val y: Z = x.y }
15+
'{ val y: t.Underlying = x.y }
1516
}
1617
}
1718
}

tests/pos-macros/i7887.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def typed[A](using t: quoted.Type[A], qctx: quoted.QuoteContext): Unit = {
22
import qctx.reflect._
33
'{
4-
type T = $t
4+
type T = A
55
${'{???}.cast[T]}
66
}
77
}

tests/pos-macros/i9020-b/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ object Show {
88
import quoted._
99
def impl[T](using ctx: QuoteContext, tpe: Type[T]): Expr[Show[T]] =
1010
'{
11-
new Show[$tpe] {
12-
def show(t: $tpe): String = "TODO"
11+
new Show[tpe.Underlying] {
12+
def show(t: tpe.Underlying): String = "TODO"
1313
}
1414
}
1515
}

tests/pos-macros/quote-1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import scala.quoted._
33
class Test(using QuoteContext) {
44

55
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
6-
val y: $t = $x
6+
val y: T = $x
77
val z = $x
88
}
99

1010
f('{2})('[Int])
1111
f('{ true })('[Boolean])
1212

1313
def g(es: Expr[String], t: Type[String]) =
14-
f('{ ($es + "!") :: Nil })('[List[$t]])
14+
f('{ ($es + "!") :: Nil })('[List[t.Underlying]])
1515
}

tests/run-macros/i7887/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def myMacroImpl(a: quoted.Expr[_])(using qctx: quoted.QuoteContext) = {
33
def typed[A] = {
44
implicit val t: quoted.Type[A] = a.unseal.tpe.widen.seal.asInstanceOf[quoted.Type[A]]
55
'{
6-
type T = $t
6+
type T = A
77
${a.unseal.seal.cast[T]}
88
}
99
}

tests/run-macros/refined-selectable-macro/Macro_2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ object Macro2 {
1414
object Record extends SelectableRecordCompanion[Record] {
1515
import scala.quoted._
1616

17-
inline def apply[R <: Record](elems: (String, Any)*) : R = ${ applyImpl('elems, '[R]) }
17+
inline def apply[R <: Record](elems: (String, Any)*) : R = ${ applyImpl[R]('elems) }
1818

19-
def applyImpl[R <: Record: Type](elems: Expr[Seq[(String, Any)]], ev: Type[R])(using qctx: QuoteContext) = {
20-
'{ new Record($elems:_*).asInstanceOf[$ev] }
19+
def applyImpl[R <: Record: Type](elems: Expr[Seq[(String, Any)]])(using qctx: QuoteContext) = {
20+
'{ new Record($elems:_*).asInstanceOf[R] }
2121
}
2222

2323
def fromUntypedTuple(elems: (String, Any)*): Record = Record(elems: _*)

0 commit comments

Comments
 (0)