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

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

tests/run-with-compiler/i3947d2.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.Foo])
17-
test(classOf[foo.Foo#Bar])
18-
test(classOf[foo.Foo.Baz])
15+
'{
16+
${test(classOf[foo.Foo])}
17+
${test(classOf[foo.Foo#Bar])}
18+
${test(classOf[foo.Foo.Baz])}
19+
}
1920
}
2021

2122
}

tests/run-with-compiler/i3947e.check

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

tests/run-with-compiler/i3947e.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@
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)
7+
def main(args: Array[String]): Unit = run {
88

9-
def test[T: Type](clazz: java.lang.Class[T]): Unit = run {
9+
def test[T: Type](clazz: java.lang.Class[T]) = {
1010
val lclazz = clazz.toExpr
1111
val name = '{ ($lclazz).getCanonicalName }
12-
println()
1312
println(name.show)
1413
'{ println($name) }
1514
}
1615

17-
// class Object
18-
test(classOf[Array[_]])
16+
'{
17+
// class Object
18+
${test(classOf[Array[_]])}
1919

20-
// class Array[Foo]
21-
test(classOf[Array[Foo]])
20+
// class Array[Foo]
21+
${test(classOf[Array[Foo]])}
2222

23-
// class Array[Array[Foo]]
24-
test(classOf[Array[Array[Foo]]])
23+
// class Array[Array[Foo]]
24+
${test(classOf[Array[Array[Foo]]])}
25+
}
2526
}
2627

2728
}

tests/run-with-compiler/i3947f.check

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

tests/run-with-compiler/i3947f.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ 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+
8+
def main(args: Array[String]): Unit = run {
9+
def test[T: Type](clazz: java.lang.Class[T]) = {
910
val lclazz = clazz.toExpr
1011
val name = '{ ($lclazz).getCanonicalName }
11-
println()
1212
println(name.show)
1313
'{ println($name) }
1414
}
1515

1616
// class Array[Object]
17-
test(classOf[Array[Any]])
18-
test(classOf[Array[AnyVal]])
19-
test(classOf[Array[AnyRef]])
20-
test(classOf[Array[Object]])
17+
'{
18+
${test(classOf[Array[Any]])}
19+
${test(classOf[Array[AnyVal]])}
20+
${test(classOf[Array[AnyRef]])}
21+
${test(classOf[Array[Object]])}
22+
}
2123
}
2224

2325
}

tests/run-with-compiler/i3947g.check

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
21
scala.Predef.classOf[scala.Array[scala.Boolean]].getCanonicalName()
3-
boolean[]
4-
52
scala.Predef.classOf[scala.Array[scala.Byte]].getCanonicalName()
6-
byte[]
7-
83
scala.Predef.classOf[scala.Array[scala.Char]].getCanonicalName()
9-
char[]
10-
114
scala.Predef.classOf[scala.Array[scala.Short]].getCanonicalName()
5+
boolean[]
6+
byte[]
7+
char[]
128
short[]

tests/run-with-compiler/i3947g.scala

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

44
object Test {
5-
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 {
5+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
6+
def main(args: Array[String]): Unit = run {
7+
def test[T: Type](clazz: java.lang.Class[T]) = {
98
val lclazz = clazz.toExpr
109
val name = '{ ($lclazz).getCanonicalName }
11-
println()
1210
println(name.show)
1311
'{ println($name) }
1412
}
1513

1614
// primitive arrays
17-
test(classOf[Array[Boolean]])
18-
test(classOf[Array[Byte]])
19-
test(classOf[Array[Char]])
20-
test(classOf[Array[Short]])
15+
'{
16+
${test(classOf[Array[Boolean]])}
17+
${test(classOf[Array[Byte]])}
18+
${test(classOf[Array[Char]])}
19+
${test(classOf[Array[Short]])}
20+
}
2121
}
2222

2323
}

tests/run-with-compiler/i3947i.check

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
21
scala.Predef.classOf[scala.Array[scala.Int]].getCanonicalName()
3-
int[]
4-
52
scala.Predef.classOf[scala.Array[scala.Long]].getCanonicalName()
6-
long[]
7-
83
scala.Predef.classOf[scala.Array[scala.Float]].getCanonicalName()
9-
float[]
10-
114
scala.Predef.classOf[scala.Array[scala.Double]].getCanonicalName()
5+
int[]
6+
long[]
7+
float[]
128
double[]

tests/run-with-compiler/i3947i.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
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

1615
// primitive arrays
17-
test(classOf[Array[Int]])
18-
test(classOf[Array[Long]])
19-
test(classOf[Array[Float]])
20-
test(classOf[Array[Double]])
16+
'{
17+
${test(classOf[Array[Int]])}
18+
${test(classOf[Array[Long]])}
19+
${test(classOf[Array[Float]])}
20+
${test(classOf[Array[Double]])}
21+
}
2122
}
2223

2324
}

0 commit comments

Comments
 (0)