From aef8d7cf78f52f41f26d7d0e26fb311806219218 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 23 Apr 2021 15:32:47 +0200 Subject: [PATCH] Correct generic signature for intersection involving Array We can't just check the class symbol since both `Array[Int]` and `Array[String]` have the same symbol but different erasure. Fixes #12204. --- .../src/dotty/tools/dotc/transform/GenericSignatures.scala | 4 ++-- tests/run/i12204/A_1.scala | 3 +++ tests/run/i12204/B_2.java | 5 +++++ tests/run/i12204/Test_3.scala | 5 +++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/run/i12204/A_1.scala create mode 100644 tests/run/i12204/B_2.java create mode 100644 tests/run/i12204/Test_3.scala diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index e2977a03e804..4348bee27ff5 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -131,10 +131,10 @@ object GenericSignatures { */ def splitIntersection(parents: List[Type])(using Context): (List[Type], List[Type]) = val erasedParents = parents.map(erasure) - val erasedCls = erasedGlb(erasedParents).classSymbol + val erasedTp = erasedGlb(erasedParents) parents.zip(erasedParents) .partitionMap((parent, erasedParent) => - if erasedParent.classSymbol eq erasedCls then + if erasedParent =:= erasedTp then Left(parent) else Right(parent)) diff --git a/tests/run/i12204/A_1.scala b/tests/run/i12204/A_1.scala new file mode 100644 index 000000000000..95b519fa066a --- /dev/null +++ b/tests/run/i12204/A_1.scala @@ -0,0 +1,3 @@ +object A { + def intARRAY_131(x: Array[String] with Array[Int]): Unit = {} +} diff --git a/tests/run/i12204/B_2.java b/tests/run/i12204/B_2.java new file mode 100644 index 000000000000..283e63a8974b --- /dev/null +++ b/tests/run/i12204/B_2.java @@ -0,0 +1,5 @@ +public class B_2 { + public static void test() { + A.intARRAY_131(null); // shouldn't throw a NoSuchMethodError + } +} diff --git a/tests/run/i12204/Test_3.scala b/tests/run/i12204/Test_3.scala new file mode 100644 index 000000000000..51ec04559ca7 --- /dev/null +++ b/tests/run/i12204/Test_3.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + B_2.test() + } +}