Skip to content

Commit

Permalink
fix scala#13131: escape java array in ClassTag
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha authored and tanishiking committed Aug 10, 2021
1 parent f51da32 commit 7f88e75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 4 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
if defn.SpecialClassTagClasses.contains(sym) then
classTag.select(sym.name.toTermName)
else
val clsOfType = erasure(tp) match
case JavaArrayType(elemType) => defn.ArrayOf(elemType)
case etp => etp
val clsOfType = escapeJavaArray(erasure(tp))
classTag.select(nme.apply).appliedToType(tp).appliedTo(clsOf(clsOfType))
tag.withSpan(span)
case tp => EmptyTree
Expand Down Expand Up @@ -375,9 +373,9 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
synthesizedSumMirror(formal, span)
case _ => EmptyTree

private def escapeJavaArray(elemTp: Type)(using Context): Type = elemTp match
case JavaArrayType(elemTp1) => defn.ArrayOf(escapeJavaArray(elemTp1))
case _ => elemTp
private def escapeJavaArray(tp: Type)(using Context): Type = tp match
case JavaArrayType(elemTp) => defn.ArrayOf(escapeJavaArray(elemTp))
case _ => tp

private enum ManifestKind:
case Full, Opt, Clss
Expand Down
4 changes: 4 additions & 0 deletions tests/run/i13131.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@main def Test =
val `ct_[[I` = reflect.classTag[Array[Array[Int]] | Array[Array[Int]]]
val arrArrInt = Array(Array(1))
assert(`ct_[[I`.runtimeClass == arrArrInt.getClass)

0 comments on commit 7f88e75

Please sign in to comment.