From 687bd19e8e7476db9a79b2920233a880c51ea0fe Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Mon, 26 Jul 2021 14:43:34 +0200 Subject: [PATCH] fix #13131: escape java array in ClassTag --- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 10 ++++------ tests/run/i13131.scala | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 tests/run/i13131.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 983d3be2ff20..f66000c714e5 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -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 @@ -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 diff --git a/tests/run/i13131.scala b/tests/run/i13131.scala new file mode 100644 index 000000000000..0c9661ffa75a --- /dev/null +++ b/tests/run/i13131.scala @@ -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)