From 8d043f4a1b65ad695b46c2b186a011e2b1419b5f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 9 Feb 2021 15:42:50 +0100 Subject: [PATCH] Don't generate JavaArrayTypes in class constants E.g. generate Array[Int] instead of []Int. Fixes #11353 --- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 5 ++++- tests/pos/i11353.scala | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i11353.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 445c130e50fb..db6f5f9f60c0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -39,7 +39,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): if defn.SpecialClassTagClasses.contains(sym) then classTag.select(sym.name.toTermName) else - classTag.select(nme.apply).appliedToType(tp).appliedTo(clsOf(erasure(tp))) + val clsOfType = erasure(tp) match + case JavaArrayType(elemType) => defn.ArrayOf(elemType) + case etp => etp + classTag.select(nme.apply).appliedToType(tp).appliedTo(clsOf(clsOfType)) tag.withSpan(span) case tp => EmptyTree case _ => EmptyTree diff --git a/tests/pos/i11353.scala b/tests/pos/i11353.scala new file mode 100644 index 000000000000..cca655cf049b --- /dev/null +++ b/tests/pos/i11353.scala @@ -0,0 +1,10 @@ +def iarr = IArray( + IArray(1, 2, 3), + IArray(4, 5, 6), + IArray(7, 8, 9) +) +def arr = Array( // same issue + IArray(1, 2, 3), + Array(4, 5, 6), + Array(7, 8, 9) +)