Skip to content

Commit 9ec34f8

Browse files
Merge pull request #10110 from dotty-staging/use-canonical-undelying-type
Use canonical underlying type reference
2 parents 1f433d5 + a779493 commit 9ec34f8

25 files changed

+54
-55
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class ReifyQuotes extends MacroTransform {
7777
case tree: RefTree if !Inliner.inInlineMethod =>
7878
assert(!tree.symbol.isQuote)
7979
assert(!tree.symbol.isExprSplice)
80-
assert(!tree.symbol.isTypeSplice)
8180
case _ : TypeDef =>
8281
assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot),
8382
s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag")
@@ -210,16 +209,15 @@ class ReifyQuotes extends MacroTransform {
210209
* are in the body of an inline method.
211210
*/
212211
protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree =
213-
if (level > 1) {
212+
if level > 1 then
214213
val body1 = nested(isQuote = false).transform(body)(using spliceContext)
215214
cpy.Select(splice)(body1, splice.name)
216-
}
217-
else {
218-
assert(level == 1, "unexpected top splice outside quote")
215+
else if level == 1 then
219216
val (body1, quotes) = nested(isQuote = false).splitSplice(body)(using spliceContext)
220217
val tpe = outer.embedded.getHoleType(body, splice)
221218
makeHole(splice.isTerm, body1, quotes, tpe).withSpan(splice.span)
222-
}
219+
else
220+
splice
223221

224222
/** Transforms the contents of a nested splice
225223
* Assuming

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) }
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/neg-macros/i4774b.scala renamed to tests/pos-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](
88
'y
99
)}
1010
}

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 = Type[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] = Type[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] = Type[Z]
14-
'{ val y: $t = x.y }
14+
'{ val y: Z = x.y }
15+
'{ val y: t.Underlying = x.y }
1516
}
1617
}
1718
}

0 commit comments

Comments
 (0)