Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ trait Applications extends Compatibility {
if tycon1 =:= tycon2 && args1.length == args2.length =>
args1.lazyZip(args2).forall {
case (TypeBounds(_, hi), formal) => hi relaxed_<:< formal
case (arg, formal) => arg =:= formal
}
case _ => false
case _ => false
Expand Down
9 changes: 8 additions & 1 deletion tests/run/overload_repeated/A_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class A_1 {
public static <T> int foo9(Class<? extends T> a) { return 1; } // (a)
public static <T extends Number> int foo9(Class<T> a, int... ints) { return 2; } // (b)

// https://github.com/scala/scala3/issues/25000
// Mixed wildcard/concrete type args - tests that wildcardArgOK handles
// non-TypeBounds args correctly
public static <V> int foo10(java.util.Map<String, ? extends V> a) { return 1; }
public static <V> int foo10(java.util.Map<String, V> a, int... ints) { return 2; }

public static boolean check() {
// Java prefers non-varargs to varargs:
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2
Expand All @@ -39,6 +45,7 @@ public static boolean check() {
foo6(Object.class) == 1 &&
foo7(Integer.class) == 1 &&
foo8(Integer.class) == 1 &&
foo9(Integer.class) == 1;
foo9(Integer.class) == 1 &&
foo10(new java.util.HashMap<String, Object>()) == 1;
}
}
9 changes: 9 additions & 0 deletions tests/run/overload_repeated/B_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ object Test {
def bar9[T](a: Class[? <: T]): Int = 1 // (a)
def bar9[T <: Number](a: Class[T], ints: Int*): Int = 2 // (b)

// Mixed wildcard/concrete type args - tests that wildcardArgOK handles
// non-TypeBounds args correctly, using java.util.Map which is invariant
// see: https://github.com/scala/scala3/issues/25000
def bar10[V](a: java.util.Map[String, ? <: V]): Int = 1
def bar10[V](a: java.util.Map[String, V], ints: Int*): Int = 2

def main(args: Array[String]): Unit = {
// In Java, varargs are always less specific than non-varargs (see
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2),
Expand All @@ -43,6 +49,8 @@ object Test {
assert(A_1.foo7(classOf[Integer]) == 1) // Same as in Java and Scala 2
assert(A_1.foo8(classOf[Integer]) == 1) // Same as in Java and Scala 2
// assert(A_1.foo9(classOf[Integer]) == 1) // Works in Java, ambiguous in Scala 2 and 3
val javaMap: java.util.Map[String, ? <: Object] = new java.util.HashMap()
assert(A_1.foo10(javaMap) == 1) // Same as in Java

// Same with Scala varargs:
// assert(bar1("") == 1) // Works in Java, ambiguous in Scala 2 and Dotty
Expand All @@ -54,5 +62,6 @@ object Test {
assert(bar7(classOf[Integer]) == 1) // same in Scala2
assert(bar8(classOf[Integer]) == 1) // same in Scala2
// assert(bar9(classOf[Integer]) == 1) Works in Java, ambiguous in Scala 2 and 3
assert(bar10(javaMap) == 1)
}
}
Loading