Skip to content

fix #13131: escape java array in ClassTag #13156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)