Skip to content

Commit 7400cee

Browse files
committed
Support array classes
1 parent 7991c78 commit 7400cee

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ object PickledQuotes {
171171
else if (clazz == classOf[Float]) defn.FloatType
172172
else if (clazz == classOf[Double]) defn.DoubleType
173173
else defn.UnitType
174+
} else if (clazz.isArray) {
175+
defn.ArrayType.appliedTo(classToType(clazz.getComponentType))
174176
} else if (clazz.isMemberClass) {
175177
val name = clazz.getSimpleName.toTypeName
176178
val enclosing = classToType(clazz.getEnclosingClass)

tests/run-with-compiler/i3947e.check

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
classOf[Object].getCanonicalName()
3+
java.lang.Object
4+
5+
classOf[Array[Object]].getCanonicalName()
6+
java.lang.Object[]
7+
8+
classOf[Array[Object]].getCanonicalName()
9+
java.lang.Object[]
10+
11+
classOf[Array[Object]].getCanonicalName()
12+
java.lang.Object[]
13+
14+
classOf[Array[Object]].getCanonicalName()
15+
java.lang.Object[]
16+
17+
classOf[Array[Foo]].getCanonicalName()
18+
Foo[]
19+
20+
classOf[Array[Array[Foo]]].getCanonicalName()
21+
Foo[][]

tests/run-with-compiler/i3947e.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import scala.quoted._
3+
import dotty.tools.dotc.quoted.Toolbox._
4+
5+
object Test {
6+
7+
def main(args: Array[String]): Unit = {
8+
9+
def test[T](clazz: java.lang.Class[T]): Unit = {
10+
val lclazz = clazz.toExpr
11+
val name = '{ (~clazz.toExpr).getCanonicalName }
12+
println()
13+
println(name.show)
14+
println(name.run)
15+
}
16+
17+
// class Object
18+
test(classOf[Array[_]])
19+
20+
// class Array[Object]
21+
test(classOf[Array[Any]])
22+
test(classOf[Array[AnyVal]])
23+
test(classOf[Array[AnyRef]])
24+
test(classOf[Array[Object]])
25+
26+
// class Array[Foo]
27+
test(classOf[Array[Foo]])
28+
29+
// class Array[Array[Foo]]
30+
test(classOf[Array[Array[Foo]]])
31+
}
32+
33+
}
34+
35+
class Foo

tests/run-with-compiler/i3947f.check

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
classOf[Array[Boolean]].getCanonicalName()
3+
boolean[]
4+
5+
classOf[Array[Byte]].getCanonicalName()
6+
byte[]
7+
8+
classOf[Array[Char]].getCanonicalName()
9+
char[]
10+
11+
classOf[Array[Short]].getCanonicalName()
12+
short[]
13+
14+
classOf[Array[Int]].getCanonicalName()
15+
int[]
16+
17+
classOf[Array[Long]].getCanonicalName()
18+
long[]
19+
20+
classOf[Array[Float]].getCanonicalName()
21+
float[]
22+
23+
classOf[Array[Double]].getCanonicalName()
24+
double[]
25+
26+
classOf[Array[Array[Int]]].getCanonicalName()
27+
int[][]
28+
29+
classOf[Array[Array[Array[Int]]]].getCanonicalName()
30+
int[][][]

tests/run-with-compiler/i3947f.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import scala.quoted._
3+
import dotty.tools.dotc.quoted.Toolbox._
4+
5+
object Test {
6+
7+
def main(args: Array[String]): Unit = {
8+
9+
def test[T](clazz: java.lang.Class[T]): Unit = {
10+
val lclazz = clazz.toExpr
11+
val name = '{ (~clazz.toExpr).getCanonicalName }
12+
println()
13+
println(name.show)
14+
println(name.run)
15+
}
16+
17+
// primitive arrays
18+
test(classOf[Array[Boolean]])
19+
test(classOf[Array[Byte]])
20+
test(classOf[Array[Char]])
21+
test(classOf[Array[Short]])
22+
test(classOf[Array[Int]])
23+
test(classOf[Array[Long]])
24+
test(classOf[Array[Float]])
25+
test(classOf[Array[Double]])
26+
27+
test(classOf[Array[Array[Int]]])
28+
test(classOf[Array[Array[Array[Int]]]])
29+
}
30+
31+
}

0 commit comments

Comments
 (0)