Skip to content

Commit aef8d7c

Browse files
committed
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.
1 parent 08dda0d commit aef8d7c

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ object GenericSignatures {
131131
*/
132132
def splitIntersection(parents: List[Type])(using Context): (List[Type], List[Type]) =
133133
val erasedParents = parents.map(erasure)
134-
val erasedCls = erasedGlb(erasedParents).classSymbol
134+
val erasedTp = erasedGlb(erasedParents)
135135
parents.zip(erasedParents)
136136
.partitionMap((parent, erasedParent) =>
137-
if erasedParent.classSymbol eq erasedCls then
137+
if erasedParent =:= erasedTp then
138138
Left(parent)
139139
else
140140
Right(parent))

tests/run/i12204/A_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object A {
2+
def intARRAY_131(x: Array[String] with Array[Int]): Unit = {}
3+
}

tests/run/i12204/B_2.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class B_2 {
2+
public static void test() {
3+
A.intARRAY_131(null); // shouldn't throw a NoSuchMethodError
4+
}
5+
}

tests/run/i12204/Test_3.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
B_2.test()
4+
}
5+
}

0 commit comments

Comments
 (0)