Skip to content

Commit

Permalink
Merge pull request #13156 from dotty-staging/fix-13131
Browse files Browse the repository at this point in the history
fix #13131: escape java array in ClassTag
  • Loading branch information
smarter authored Jul 26, 2021
2 parents 809a628 + 687bd19 commit e392fee
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 e392fee

Please sign in to comment.