@@ -993,7 +993,29 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
993993 (sym1 eq NullClass ) && isNullable(tp2)
994994 }
995995 case tp1 @ AppliedType (tycon1, args1) =>
996- compareAppliedType1(tp1, tycon1, args1)
996+ // Special case: Java arrays are covariant.
997+ // When checking overrides (frozenConstraint), allow B[] <: A[] if B <: A
998+ // for Java-defined types.
999+ def checkJavaArrayCovariance : Boolean = tp2 match {
1000+ case AppliedType (tycon2, arg2 :: Nil )
1001+ if frozenConstraint // for override checking (frozen_<:)
1002+ && tycon1.typeSymbol == defn.ArrayClass
1003+ && tycon2.typeSymbol == defn.ArrayClass
1004+ && args1.length == 1 =>
1005+ // Check if element types are Java-defined to detect Java arrays
1006+ val elem1Sym = args1.head.typeSymbol
1007+ val elem2Sym = arg2.typeSymbol
1008+ if elem1Sym.exists && elem2Sym.exists
1009+ && elem1Sym.is(JavaDefined ) && elem2Sym.is(JavaDefined )
1010+ then
1011+ // Arrays are covariant in Java: B[] <: A[] if B <: A
1012+ isSubType(args1.head, arg2)
1013+ else
1014+ false
1015+ case _ => false
1016+ }
1017+
1018+ checkJavaArrayCovariance || compareAppliedType1(tp1, tycon1, args1)
9971019 case tp1 : SingletonType =>
9981020 def comparePaths = tp2 match
9991021 case tp2 : (TermRef | ThisType ) =>
0 commit comments