Skip to content

Commit c67b6c9

Browse files
Merge pull request #6958 from dotty-staging/contextualize-type-splices
Contextualize type splices
2 parents e68bc3b + bff3dd7 commit c67b6c9

File tree

21 files changed

+106
-126
lines changed

21 files changed

+106
-126
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,10 @@ class ReifyQuotes extends MacroTransform {
239239
meth.appliedTo(pickledQuoteStrings, splicesList)
240240
}
241241

242-
if (splices.nonEmpty) pickleAsTasty()
243-
else if (isType) {
242+
if (isType) {
244243
def tag(tagName: String) = ref(defn.QuotedTypeModule).select(tagName.toTermName).appliedTo(qctx)
245-
if (body.symbol.isPrimitiveValueClass) tag(s"${body.symbol.name}Tag")
246-
else pickleAsTasty()
244+
if (splices.isEmpty && body.symbol.isPrimitiveValueClass) tag(s"${body.symbol.name}Tag")
245+
else pickleAsTasty().select(nme.apply).appliedTo(qctx)
247246
}
248247
else toValue(body) match {
249248
case Some(value) => pickleAsValue(value)

library/src/scala/runtime/quoted/Unpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ object Unpickler {
1919
/** Unpickle `repr` which represents a pickled `Type` tree,
2020
* replacing splice nodes with `args`
2121
*/
22-
def unpickleType[T](repr: Pickled, args: Seq[Seq[Any] => Type[_]]): Type[T] = new TastyType[T](repr, args)
22+
def unpickleType[T](repr: Pickled, args: Seq[Seq[Any] => Type[_]]): given QuoteContext => Type[T] = new TastyType[T](repr, args)
23+
2324
}

tests/pos/i4414.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import scala.quoted._
22

33
object Test {
4+
given as QuoteContext = ???
45

56
def a[A: Type](): Unit = {
67
b[Expr[A]]()

tests/run-with-compiler/i3947.check

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
21
scala.Predef.classOf[java.lang.Object].getCanonicalName()
3-
java.lang.Object
4-
52
scala.Predef.classOf[java.lang.Object].getCanonicalName()
6-
java.lang.Object
7-
83
scala.Predef.classOf[java.lang.Object].getCanonicalName()
9-
java.lang.Object
10-
114
scala.Predef.classOf[java.lang.Object].getCanonicalName()
125
java.lang.Object
6+
java.lang.Object
7+
java.lang.Object
8+
java.lang.Object

tests/run-with-compiler/i3947.scala

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

44
object Test {
55

6-
def main(args: Array[String]): Unit = {
7-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
8-
def test[T: Type](clazz: java.lang.Class[T]): Unit = run {
6+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
7+
def main(args: Array[String]): Unit = run {
8+
def test[T: Type](clazz: java.lang.Class[T]) = {
99
val lclazz = clazz.toExpr
1010
val name = '{ ($lclazz).getCanonicalName }
11-
println()
1211
println(name.show)
1312
'{ println($name) }
1413
}
1514

1615
// classOf[Object]
17-
test(classOf[Object])
18-
test(classOf[Any])
19-
test(classOf[AnyRef])
20-
test(classOf[AnyVal])
16+
'{
17+
${test(classOf[Object])}
18+
${test(classOf[Any])}
19+
${test(classOf[AnyRef])}
20+
${test(classOf[AnyVal])}
21+
}
2122
}
2223

2324
}

tests/run-with-compiler/i3947c.check

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
21
scala.Predef.classOf[scala.runtime.Null].getCanonicalName()
3-
scala.runtime.Null$
4-
52
scala.Predef.classOf[scala.runtime.Nothing].getCanonicalName()
6-
scala.runtime.Nothing$
7-
83
scala.Predef.classOf[java.lang.String].getCanonicalName()
4+
scala.runtime.Null$
5+
scala.runtime.Nothing$
96
java.lang.String

tests/run-with-compiler/i3947c.scala

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

44
object Test {
5+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
56

6-
def main(args: Array[String]): Unit = {
7-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
8-
def test[T: Type](clazz: java.lang.Class[T]): Unit = run {
7+
def main(args: Array[String]): Unit = run {
8+
def test[T: Type](clazz: java.lang.Class[T]) = {
99
val lclazz = clazz.toExpr
1010
val name = '{ ($lclazz).getCanonicalName }
11-
println()
1211
println(name.show)
1312
'{ println($name) }
1413
}
1514

16-
test(classOf[Null])
17-
test(classOf[Nothing])
15+
'{
16+
${test(classOf[Null])}
17+
${test(classOf[Nothing])}
1818

19-
test(classOf[String])
19+
${test(classOf[String])}
20+
}
2021
}
2122

2223
}

tests/run-with-compiler/i3947d.check

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
21
scala.Predef.classOf[Foo].getCanonicalName()
3-
Foo
4-
52
scala.Predef.classOf[Foo#Bar].getCanonicalName()
6-
Foo.Bar
7-
83
scala.Predef.classOf[Foo.Baz].getCanonicalName()
4+
Foo
5+
Foo.Bar
96
Foo.Baz

tests/run-with-compiler/i3947d.scala

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

44
object Test {
5+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
56

6-
def main(args: Array[String]): Unit = {
7-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
8-
def test[T: Type](clazz: java.lang.Class[T]): Unit = run {
7+
def main(args: Array[String]): Unit = run {
8+
def test[T: Type](clazz: java.lang.Class[T]) = {
99
val lclazz = clazz.toExpr
1010
val name = '{ ($lclazz).getCanonicalName }
11-
println()
1211
println(name.show)
1312
'{ println($name) }
1413
}
1514

16-
test(classOf[Foo])
17-
test(classOf[Foo#Bar])
18-
test(classOf[Foo.Baz])
15+
'{
16+
${test(classOf[Foo])}
17+
${test(classOf[Foo#Bar])}
18+
${test(classOf[Foo.Baz])}
19+
}
1920
}
2021

2122
}

tests/run-with-compiler/i3947d2.check

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
21
scala.Predef.classOf[foo.Foo].getCanonicalName()
3-
foo.Foo
4-
52
scala.Predef.classOf[foo.Foo#Bar].getCanonicalName()
6-
foo.Foo.Bar
7-
83
scala.Predef.classOf[foo.Foo.Baz].getCanonicalName()
4+
foo.Foo
5+
foo.Foo.Bar
96
foo.Foo.Baz

0 commit comments

Comments
 (0)