diff --git a/compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala b/compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala index 37f32a9b2b16..c1b3174397f6 100644 --- a/compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala +++ b/compiler/src/dotty/tools/dotc/core/JavaNullInterop.scala @@ -114,7 +114,7 @@ object JavaNullInterop { // This is because `setNames(null)` passes as argument a single-element array containing the value `null`, // and not a `null` array. || !ctx.flexibleTypes && tp.isRef(defn.RepeatedParamClass) - case _ => true + case _ => false })) override def apply(tp: Type): Type = tp match { diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 9501e51aeb6f..2260a666bb1b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -645,14 +645,15 @@ trait Applications extends Compatibility { missingArg(n) } - if (formal.isRepeatedParam) + val formal1 = formal.stripFlexible + if (formal1.isRepeatedParam) args match { case arg :: Nil if isVarArg(arg) => addTyped(arg) case (arg @ Typed(Literal(Constant(null)), _)) :: Nil if ctx.isAfterTyper => addTyped(arg) case _ => - val elemFormal = formal.widenExpr.argTypesLo.head + val elemFormal = formal1.widenExpr.argTypesLo.head val typedArgs = harmonic(harmonizeArgs, elemFormal) { args.map { arg => diff --git a/tests/explicit-nulls/flexible-types/common/interop-propagate.scala b/tests/explicit-nulls/flexible-types/common/interop-propagate.scala index 9be5ed26d8e3..40eb12dd287c 100644 --- a/tests/explicit-nulls/flexible-types/common/interop-propagate.scala +++ b/tests/explicit-nulls/flexible-types/common/interop-propagate.scala @@ -3,16 +3,16 @@ // Test that type mapping works with flexible types. val ll: ArrayList[ArrayList[ArrayList[String]]] = new ArrayList[ArrayList[ArrayList[String]]] - val level1: ArrayList[ArrayList[String]] = ll.get(0) - val level2: ArrayList[String] = ll.get(0).get(0) - val level3: String = ll.get(0).get(0).get(0) + val level1: ArrayList[ArrayList[String]] = ll.get(0) // error + val level2: ArrayList[String] = ll.get(0).get(0) // error + val level3: String = ll.get(0).get(0).get(0) // error val lb = new ArrayList[ArrayList[ArrayList[String]]] val levelA = lb.get(0) - val levelB = lb.get(0).get(0) - val levelC = lb.get(0).get(0).get(0) + val levelB = lb.get(0).get(0) // error + val levelC = lb.get(0).get(0).get(0) // error - val x = levelA.get(0) + val x = levelA.get(0) // error val y = levelB.get(0) - val z: String = levelA.get(0).get(0) + val z: String = levelA.get(0).get(0) // error } diff --git a/tests/explicit-nulls/flexible-types/common/java-call/S.scala b/tests/explicit-nulls/flexible-types/common/java-call/S.scala index 5c4b9c1ed8f7..e5f9abe70d5f 100644 --- a/tests/explicit-nulls/flexible-types/common/java-call/S.scala +++ b/tests/explicit-nulls/flexible-types/common/java-call/S.scala @@ -10,7 +10,7 @@ val s1n: String | Null = j.f1() val i1: Int = j.f2() -val k: jj.K = jj.f3() +val k: jj.K = jj.f3() // error // error val s2: String = j.g1[String]() // error diff --git a/tests/explicit-nulls/flexible-types/common/unsafe-match-null.scala b/tests/explicit-nulls/flexible-types/common/unsafe-match-null.scala deleted file mode 100644 index 2055f51af5cd..000000000000 --- a/tests/explicit-nulls/flexible-types/common/unsafe-match-null.scala +++ /dev/null @@ -1,5 +0,0 @@ -def test1 = - val s: String = ??? - s.trim() match - case _: String => - case null => // error: Values of types Null and String cannot be compared diff --git a/tests/explicit-nulls/flexible-types/common/equal/J.java b/tests/explicit-nulls/flexible-types/pos/equal/J.java similarity index 100% rename from tests/explicit-nulls/flexible-types/common/equal/J.java rename to tests/explicit-nulls/flexible-types/pos/equal/J.java diff --git a/tests/explicit-nulls/flexible-types/common/equal/S.scala b/tests/explicit-nulls/flexible-types/pos/equal/S.scala similarity index 100% rename from tests/explicit-nulls/flexible-types/common/equal/S.scala rename to tests/explicit-nulls/flexible-types/pos/equal/S.scala diff --git a/tests/flexible-types/pos/interop-constructor-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-constructor-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-constructor-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-constructor-src/J.java diff --git a/tests/flexible-types/pos/interop-constructor-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-constructor-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-constructor-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-constructor-src/S.scala diff --git a/tests/flexible-types/pos/interop-enum-src/Day.java b/tests/explicit-nulls/flexible-types/pos/interop-enum-src/Day.java similarity index 100% rename from tests/flexible-types/pos/interop-enum-src/Day.java rename to tests/explicit-nulls/flexible-types/pos/interop-enum-src/Day.java diff --git a/tests/flexible-types/pos/interop-enum-src/Planet.java b/tests/explicit-nulls/flexible-types/pos/interop-enum-src/Planet.java similarity index 100% rename from tests/flexible-types/pos/interop-enum-src/Planet.java rename to tests/explicit-nulls/flexible-types/pos/interop-enum-src/Planet.java diff --git a/tests/flexible-types/pos/interop-enum-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-enum-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-enum-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-enum-src/S.scala diff --git a/tests/flexible-types/pos/interop-generics/J.java b/tests/explicit-nulls/flexible-types/pos/interop-generics/J.java similarity index 100% rename from tests/flexible-types/pos/interop-generics/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-generics/J.java diff --git a/tests/flexible-types/pos/interop-generics/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-generics/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-generics/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-generics/S.scala diff --git a/tests/flexible-types/pos/interop-match-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-match-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-match-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-match-src/J.java diff --git a/tests/flexible-types/pos/interop-match-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-match-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-match-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-match-src/S.scala diff --git a/tests/flexible-types/pos/interop-method-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-method-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-method-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-method-src/J.java diff --git a/tests/flexible-types/pos/interop-method-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-method-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-method-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-method-src/S.scala diff --git a/tests/flexible-types/pos/interop-ortype-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-ortype-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-ortype-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-ortype-src/J.java diff --git a/tests/flexible-types/pos/interop-ortype-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-ortype-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-ortype-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-ortype-src/S.scala diff --git a/tests/flexible-types/pos/interop-poly-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-poly-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-poly-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-poly-src/J.java diff --git a/tests/flexible-types/pos/interop-poly-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-poly-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-poly-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-poly-src/S.scala diff --git a/tests/flexible-types/pos/interop-sam-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-sam-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-sam-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-sam-src/J.java diff --git a/tests/flexible-types/pos/interop-sam-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-sam-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-sam-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-sam-src/S.scala diff --git a/tests/flexible-types/pos/interop-static-src/J.java b/tests/explicit-nulls/flexible-types/pos/interop-static-src/J.java similarity index 100% rename from tests/flexible-types/pos/interop-static-src/J.java rename to tests/explicit-nulls/flexible-types/pos/interop-static-src/J.java diff --git a/tests/flexible-types/pos/interop-static-src/S.scala b/tests/explicit-nulls/flexible-types/pos/interop-static-src/S.scala similarity index 100% rename from tests/flexible-types/pos/interop-static-src/S.scala rename to tests/explicit-nulls/flexible-types/pos/interop-static-src/S.scala diff --git a/tests/explicit-nulls/flexible-types/pos/match-null.scala b/tests/explicit-nulls/flexible-types/pos/match-null.scala new file mode 100644 index 000000000000..4cdf7632fa35 --- /dev/null +++ b/tests/explicit-nulls/flexible-types/pos/match-null.scala @@ -0,0 +1,5 @@ +def test1 = + val s: String = ??? + s.trim() match + case _: String => + case null => diff --git a/tests/flexible-types/neg/array.scala b/tests/flexible-types/neg/array.scala deleted file mode 100644 index 83e39cc80929..000000000000 --- a/tests/flexible-types/neg/array.scala +++ /dev/null @@ -1,44 +0,0 @@ -// Test array with nulls. - -class ArrayWithNulls { - def test1 = { - // A non-nullable array of non-nullable strings - val a1: Array[String] = Array("hello") - val s1: String = a1(0) - val s2: String | Null = a1(0) - val a2: Array[String] = Array() - - // Array type is non-nullable - val b1: Array[String] = null // error - val b2: Array[Int] = null // error - } - - def test2 = { - // A nullable array of non-nullable strings - val a1: Array[String] | Null = null - val a2: Array[String] | Null = Array() - val a3: Array[String] | Null = Array("") - val a4: Array[String] | Null = Array("", null) // error - - // A non-nullable array of nullable strings - val b1: Array[String | Null] = Array() - val b2: Array[String | Null] = Array(null) - val b3: Array[String | Null] = Array("") - val b4: Array[String | Null] = Array("", null) - val b5: Array[String | Null] = null // error - - val s1: String = b1(0) // error - val s2: String | Null = b1(0) - - // A nullable array of nullable strings - val c1: Array[String | Null] | Null = Array() - } - - def test3 = { - val a1: Array[String] = Array() - - val a2: Array[String] | Null = a1 - - val a3: Array[String | Null] = a1 // error - } -} diff --git a/tests/flexible-types/pos-separate/interop-enum-src/Day_1.java b/tests/flexible-types/pos-separate/interop-enum-src/Day_1.java deleted file mode 100644 index b5d96e446fa8..000000000000 --- a/tests/flexible-types/pos-separate/interop-enum-src/Day_1.java +++ /dev/null @@ -1,6 +0,0 @@ - -public enum Day_1 { - SUN, - MON, - TUE -} diff --git a/tests/flexible-types/pos-separate/interop-enum-src/Planet_2.java b/tests/flexible-types/pos-separate/interop-enum-src/Planet_2.java deleted file mode 100644 index c46e92d13bea..000000000000 --- a/tests/flexible-types/pos-separate/interop-enum-src/Planet_2.java +++ /dev/null @@ -1,19 +0,0 @@ -public enum Planet_2 { - MERCURY (3.303e+23, 2.4397e6), - VENUS (4.869e+24, 6.0518e6), - EARTH (5.976e+24, 6.37814e6), - MARS (6.421e+23, 3.3972e6), - JUPITER (1.9e+27, 7.1492e7), - SATURN (5.688e+26, 6.0268e7), - URANUS (8.686e+25, 2.5559e7), - NEPTUNE (1.024e+26, 2.4746e7); - - private final double mass; // in kilograms - private final double radius; // in meters - Planet_2(double mass, double radius) { - this.mass = mass; - this.radius = radius; - } - private double mass() { return mass; } - private double radius() { return radius; } -} diff --git a/tests/flexible-types/pos-separate/interop-enum-src/S_3.scala b/tests/flexible-types/pos-separate/interop-enum-src/S_3.scala deleted file mode 100644 index 3c5c8cd451ae..000000000000 --- a/tests/flexible-types/pos-separate/interop-enum-src/S_3.scala +++ /dev/null @@ -1,6 +0,0 @@ - -// Verify that enum values aren't nullified. -class S { - val d: Day_1 = Day_1.MON - val p: Planet_2 = Planet_2.MARS -} diff --git a/tests/flexible-types/pos/i8981.scala b/tests/flexible-types/pos/i8981.scala deleted file mode 100644 index f72b508cf64e..000000000000 --- a/tests/flexible-types/pos/i8981.scala +++ /dev/null @@ -1 +0,0 @@ -class Foo extends javax.swing.JPanel \ No newline at end of file diff --git a/tests/flexible-types/pos/instanceof-nothing.scala b/tests/flexible-types/pos/instanceof-nothing.scala deleted file mode 100644 index ef5fc4ede841..000000000000 --- a/tests/flexible-types/pos/instanceof-nothing.scala +++ /dev/null @@ -1,26 +0,0 @@ -// Check that calling `asInstanceOf[Nothing]` throws a ClassCastException. -// In particular, the compiler needs access to the right method to throw -// the exception, and identifying the method uses some explicit nulls related -// logic (see ClassCastExceptionClass in Definitions.scala). - -object Test { - def main(args: Array[String]): Unit = { - val x: String = "hello" - try { - val y: Nothing = x.asInstanceOf[Nothing] - assert(false) - } catch { - case e: ClassCastException => - // ok - } - - val n: Null = null - try { - val y: Nothing = n.asInstanceOf[Nothing] - assert(false) - } catch { - case e: ClassCastException => - // ok - } - } -} diff --git a/tests/flexible-types/pos/interop-array-src/J.java b/tests/flexible-types/pos/interop-array-src/J.java deleted file mode 100644 index 741c3739b296..000000000000 --- a/tests/flexible-types/pos/interop-array-src/J.java +++ /dev/null @@ -1,13 +0,0 @@ -class J { - void foo1(String[] ss) {} - - String[] foo2() { - return new String[]{""}; - } - - void bar1(int[] is) {} - - int[] bar2() { - return new int[]{0}; - } -} diff --git a/tests/flexible-types/pos/interop-array-src/S.scala b/tests/flexible-types/pos/interop-array-src/S.scala deleted file mode 100644 index 6741ad50e351..000000000000 --- a/tests/flexible-types/pos/interop-array-src/S.scala +++ /dev/null @@ -1,25 +0,0 @@ -class S { - - val j = new J() - - def f = { - val x1: Array[String|Null]|Null = ??? - j.foo1(x1) // error: expected Array[String | Null] but got Array[String] - - val x2: Array[String | Null] = ??? - j.foo1(x2) // ok - j.foo1(null) // ok - - val y1: Array[String] = j.foo2() // error - val y2: Array[String | Null] = j.foo2() // error: expected Array[String | Null] but got Array[String] - val y3: Array[String | Null] | Null = j.foo2() - } - - def g = { - val x1: Array[Int] = ??? - j.bar1(x1) // ok - - val y1: Array[Int] = j.bar2() // error - val y2: Array[Int] | Null = j.bar2() - } -} diff --git a/tests/flexible-types/pos/interop-compare-src/J.java b/tests/flexible-types/pos/interop-compare-src/J.java deleted file mode 100644 index fcd07e47764c..000000000000 --- a/tests/flexible-types/pos/interop-compare-src/J.java +++ /dev/null @@ -1,5 +0,0 @@ -class J { - public String foo(String s) { - return s; - } -} diff --git a/tests/flexible-types/pos/interop-compare-src/S.scala b/tests/flexible-types/pos/interop-compare-src/S.scala deleted file mode 100644 index 3624a92180c6..000000000000 --- a/tests/flexible-types/pos/interop-compare-src/S.scala +++ /dev/null @@ -1,10 +0,0 @@ -@main def main() = { - val j: J = new J - if (j.foo(null) == null) { - println("null") - } - val x = j.foo("a") - if (x == null) { - println("null") - } -} diff --git a/tests/flexible-types/pos/interop-constructor.scala b/tests/flexible-types/pos/interop-constructor.scala deleted file mode 100644 index 4ebfaa752b3a..000000000000 --- a/tests/flexible-types/pos/interop-constructor.scala +++ /dev/null @@ -1,7 +0,0 @@ -// Test that constructors have a non-nullable return type. - -class Foo { - val x: java.lang.String = new java.lang.String() - val y: java.util.Date = new java.util.Date() - val v = new java.util.Vector[String](null /*stands for Collection*/) -} diff --git a/tests/flexible-types/pos/interop-java-varargs-src/Names.java b/tests/flexible-types/pos/interop-java-varargs-src/Names.java deleted file mode 100644 index e46b406749ce..000000000000 --- a/tests/flexible-types/pos/interop-java-varargs-src/Names.java +++ /dev/null @@ -1,4 +0,0 @@ - -class Names { - static void setNames(String... names) {} -} diff --git a/tests/flexible-types/pos/interop-java-varargs-src/S.scala b/tests/flexible-types/pos/interop-java-varargs-src/S.scala deleted file mode 100644 index e867202e506d..000000000000 --- a/tests/flexible-types/pos/interop-java-varargs-src/S.scala +++ /dev/null @@ -1,19 +0,0 @@ -// Test that nullification can handle Java varargs. -// For varargs, the element type is nullified, but the top level argument isn't. - -class S { - // Pass an empty array. - Names.setNames() - - // Pass a singleton array with null as an element. - Names.setNames(null) - - // Pass a singleton array. - Names.setNames("name1") - - // Multiple arguments. - Names.setNames("name1", "name2", "name3", "name4") - - // Multiple arguments, some null. - Names.setNames(null, null, "hello", "world", null) -} diff --git a/tests/flexible-types/pos/interop-java-varargs.scala b/tests/flexible-types/pos/interop-java-varargs.scala deleted file mode 100644 index 46dc388d02af..000000000000 --- a/tests/flexible-types/pos/interop-java-varargs.scala +++ /dev/null @@ -1,22 +0,0 @@ -import java.nio.file.* -import java.nio.file.Paths - -class S { - - // Paths.get is a Java method with two arguments, where the second one - // is a varargs: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html - // static Path get(String first, String... more) - // The Scala compiler converts this signature into - // def get(first: String | Null, more: (String | Null)*) - - // Test that we can avoid providing the varargs argument altogether. - Paths.get("out") - - // Test with one argument in the varargs. - Paths.get("home", "src") - Paths.get("home", null) - - // Test multiple arguments in the varargs. - Paths.get("home", "src", "compiler", "src") - Paths.get("home", null, null, null) -} diff --git a/tests/flexible-types/pos/override-java-object-arg-src/J.java b/tests/flexible-types/pos/override-java-object-arg-src/J.java deleted file mode 100644 index efcb630b7b6c..000000000000 --- a/tests/flexible-types/pos/override-java-object-arg-src/J.java +++ /dev/null @@ -1,10 +0,0 @@ - -// Copy of https://docs.oracle.com/javase/7/docs/api/javax/management/NotificationListener.html - -class Notification {}; - -interface NotificationListener { - - void handleNotification(Notification notification, Object handback); - -} diff --git a/tests/flexible-types/pos/override-java-object-arg-src/S.scala b/tests/flexible-types/pos/override-java-object-arg-src/S.scala deleted file mode 100644 index 757a3b6b1235..000000000000 --- a/tests/flexible-types/pos/override-java-object-arg-src/S.scala +++ /dev/null @@ -1,33 +0,0 @@ -// This test is like tests/pos/override-java-object-arg.scala, except that -// here we load the Java code from source, as opposed to a class file. -// In this case, the Java 'Object' type is turned into 'AnyRef', not 'Any'. - -class S { - - def bar(): Unit = { - val listener = new NotificationListener() { - override def handleNotification(n: Notification|Null, emitter: Object|Null): Unit = { - } - } - - val listener2 = new NotificationListener() { - override def handleNotification(n: Notification|Null, emitter: AnyRef|Null): Unit = { - } - } - - val listener3 = new NotificationListener() { - override def handleNotification(n: Notification|Null, emitter: Object): Unit = { - } - } - - val listener4 = new NotificationListener() { - override def handleNotification(n: Notification, emitter: Object|Null): Unit = { - } - } - - val listener5 = new NotificationListener() { - override def handleNotification(n: Notification, emitter: Object): Unit = { - } - } - } -} diff --git a/tests/flexible-types/pos/override-java-object-arg.scala b/tests/flexible-types/pos/override-java-object-arg.scala deleted file mode 100644 index 8c5a76e15a6c..000000000000 --- a/tests/flexible-types/pos/override-java-object-arg.scala +++ /dev/null @@ -1,43 +0,0 @@ -// When we load a Java class file, if a java method has an argument with type -// 'Object', it (the method argument) gets loaded by Dotty as 'Any' (as opposed to 'AnyRef'). -// This is pre-explicit-nulls behaviour. -// There is special logic in the type comparer that allows that method to be overridden -// with a corresponding argument with type 'AnyRef | Null' (or `Object | Null`). -// This test verifies that we can continue to override such methods, except that in -// the explicit nulls world we override with 'AnyRef|Null'. - -import javax.management.{Notification, NotificationEmitter, NotificationListener} - -class Foo { - - def bar(): Unit = { - val listener = new NotificationListener() { - // The second argument in the base interface is loaded with type 'Any', but we override - // it with 'AnyRef|Null'. - override def handleNotification(n: Notification|Null, emitter: Object|Null): Unit = { - } - } - - val listener2 = new NotificationListener() { - // The second argument in the base interface is loaded with type 'Any', but we override - // it with 'AnyRef|Null'. - override def handleNotification(n: Notification|Null, emitter: AnyRef|Null): Unit = { - } - } - - val listener3 = new NotificationListener() { - override def handleNotification(n: Notification|Null, emitter: Object): Unit = { - } - } - - val listener4 = new NotificationListener() { - override def handleNotification(n: Notification, emitter: Object|Null): Unit = { - } - } - - val listener5 = new NotificationListener() { - override def handleNotification(n: Notification, emitter: Object): Unit = { - } - } - } -} diff --git a/tests/flexible-types/pos/override-java-varargs/S.scala b/tests/flexible-types/pos/override-java-varargs/S.scala deleted file mode 100644 index bb98c86b455c..000000000000 --- a/tests/flexible-types/pos/override-java-varargs/S.scala +++ /dev/null @@ -1,14 +0,0 @@ -class S1 extends J { - override def foo(x: (String | Null)*): Unit = ??? - override def bar(x: String | Null, y: (String | Null)*): Unit = ??? -} - -class S2 extends J { - override def foo(x: String*): Unit = ??? - override def bar(x: String | Null, y: String*): Unit = ??? -} - -class S3 extends J { - override def foo(x: String*): Unit = ??? - override def bar(x: String, y: String*): Unit = ??? -} diff --git a/tests/flexible-types/pos/override-java/J1.java b/tests/flexible-types/pos/override-java/J1.java deleted file mode 100644 index 0c66c26fdea9..000000000000 --- a/tests/flexible-types/pos/override-java/J1.java +++ /dev/null @@ -1,4 +0,0 @@ -abstract class J1 { - abstract void foo1(String x); - abstract String foo2(); -} \ No newline at end of file diff --git a/tests/flexible-types/pos/override-java/J2.java b/tests/flexible-types/pos/override-java/J2.java deleted file mode 100644 index 8ff04d59f54f..000000000000 --- a/tests/flexible-types/pos/override-java/J2.java +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.List; - -abstract class J2 { - abstract void bar1(List xs); - abstract void bar2(List xss); - - abstract List bar3(); - abstract List bar4(); -} \ No newline at end of file diff --git a/tests/flexible-types/pos/override-java/S1.scala b/tests/flexible-types/pos/override-java/S1.scala deleted file mode 100644 index 01a95c8e0ef7..000000000000 --- a/tests/flexible-types/pos/override-java/S1.scala +++ /dev/null @@ -1,9 +0,0 @@ -class S1a extends J1 { - override def foo1(x: String | Null): Unit = ??? - override def foo2(): String | Null = ??? -} - -class S1b extends J1 { - override def foo1(x: String): Unit = ??? - override def foo2(): String = ??? -} \ No newline at end of file diff --git a/tests/flexible-types/pos/override-java/S2.scala b/tests/flexible-types/pos/override-java/S2.scala deleted file mode 100644 index ec440ca8f150..000000000000 --- a/tests/flexible-types/pos/override-java/S2.scala +++ /dev/null @@ -1,25 +0,0 @@ -import java.util.List - -class S2a extends J2 { - override def bar1(xs: List[String] | Null): Unit = ??? - override def bar2(xss: List[Array[String | Null]] | Null): Unit = ??? - - override def bar3(): List[String] | Null = ??? - override def bar4(): List[Array[String | Null]] | Null = ??? -} - -class S2b extends J2 { - override def bar1(xs: List[String]): Unit = ??? - override def bar2(xss: List[Array[String | Null]]): Unit = ??? - - override def bar3(): List[String] = ??? - override def bar4(): List[Array[String | Null]] = ??? -} - -class S2c extends J2 { - override def bar1(xs: List[String]): Unit = ??? - override def bar2(xss: List[Array[String]]): Unit = ??? - - override def bar3(): List[String] = ??? - override def bar4(): List[Array[String]] = ??? -} \ No newline at end of file diff --git a/tests/flexible-types/pos/override-type-params.scala b/tests/flexible-types/pos/override-type-params.scala deleted file mode 100644 index 7f59409a4c3c..000000000000 --- a/tests/flexible-types/pos/override-type-params.scala +++ /dev/null @@ -1,18 +0,0 @@ -// Testing relaxed overriding check for explicit nulls. -// The relaxed check is only enabled if one of the members is Java defined. - -import java.util.Comparator - -class C1[T <: AnyRef] extends Ordering[T]: - override def compare(o1: T, o2: T): Int = 0 - -// The following overriding is not allowed, because `compare` -// has already been declared in Scala class `Ordering`. -// class C2[T <: AnyRef] extends Ordering[T]: -// override def compare(o1: T | Null, o2: T | Null): Int = 0 - -class D1[T <: AnyRef] extends Comparator[T]: - override def compare(o1: T, o2: T): Int = 0 - -class D2[T <: AnyRef] extends Comparator[T]: - override def compare(o1: T | Null, o2: T | Null): Int = 0 diff --git a/tests/flexible-types/run/array/J.java b/tests/flexible-types/run/array/J.java deleted file mode 100644 index 6fb5d625b872..000000000000 --- a/tests/flexible-types/run/array/J.java +++ /dev/null @@ -1,4 +0,0 @@ -public class J { - public J(java.lang.String s) { - } -} diff --git a/tests/flexible-types/run/array/Test.scala b/tests/flexible-types/run/array/Test.scala deleted file mode 100644 index b37329cacbce..000000000000 --- a/tests/flexible-types/run/array/Test.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* -class Foo { - def err(msg: String): Nothing = { - throw new RuntimeException("Hello") - } - def retTypeNothing(): String = { - val y: String|Null = ??? - if (y == null) err("y is null!") - y - } -} -*/ - - -object Test { - def main(args: Array[String]): Unit = { - val i : Integer = new Integer(3) // Constructor with non-ref arg - val s1 : String | Null = new String("abc") // Constructor with ref arg - val s2 : String = new String("abc") // Constructor with ref arg, not null - val s3 = s1.nn.substring(0,1).substring(0,1) - val s4 = s2.substring(0,1).substring(0,1) - val s5 = s4.startsWith(s4) - // s1.substring(0,1) // error - val j : J = new J("") - println(s4) - //val f : Foo = new Foo("x") - //f.err("Hello") - //val l : List[String] = Java.returnsNull(); - //val j : J = new J - } -} diff --git a/tests/flexible-types/run/erasure.scala b/tests/flexible-types/run/erasure.scala deleted file mode 100644 index 1f43bde49a2e..000000000000 --- a/tests/flexible-types/run/erasure.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - val v: Vector[String | Null] = Vector("a", "b") - val v2: Vector[String] = Vector("a", "b") - println(v) - println(v2) - } -} diff --git a/tests/flexible-types/run/generic-java-array-src/JA.java b/tests/flexible-types/run/generic-java-array-src/JA.java deleted file mode 100644 index ccca309d4f49..000000000000 --- a/tests/flexible-types/run/generic-java-array-src/JA.java +++ /dev/null @@ -1,13 +0,0 @@ -class JA { - public static T get(T[] arr) { - return arr[0]; - } - - public static int getInt(int[] arr) { - return arr[0]; - } - - public static boolean getBool(boolean[] arr) { - return arr[0]; - } -} diff --git a/tests/flexible-types/run/generic-java-array-src/Test.scala b/tests/flexible-types/run/generic-java-array-src/Test.scala deleted file mode 100644 index 26e4886d499b..000000000000 --- a/tests/flexible-types/run/generic-java-array-src/Test.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - // This test shows that if we have a Java method that takes a generic array, - // then on the Scala side we'll need to pass a nullable array. - // i.e. with explicit nulls the previously-implicit cast becomes an explicit - // type annotation. - val x = new Array[Integer|Null](1) - x(0) = 10 - println(JA.get(x)) - - // However, if the Java method takes an array that's explicitly of a value type, - // then we can pass a non-nullable array from the Scala side. - val intArr = new Array[Int](1) - intArr(0) = 20 - println(JA.getInt(intArr)) - - val boolArr = new Array[Boolean](1) - boolArr(0) = true - println(JA.getBool(boolArr)) - } -} diff --git a/tests/flexible-types/run/i11332.scala b/tests/flexible-types/run/i11332.scala deleted file mode 100644 index 73fb48839c16..000000000000 --- a/tests/flexible-types/run/i11332.scala +++ /dev/null @@ -1,22 +0,0 @@ -// scalajs: --skip -import scala.language.unsafeNulls - -import java.lang.invoke._, MethodType.methodType - -// A copy of tests/run/i11332.scala -// to test the bootstrap minimisation which failed -// (because bootstrap runs under explicit nulls) -class Foo: - def neg(x: Int): Int = -x - -object Test: - def main(args: Array[String]): Unit = - val l = MethodHandles.lookup() - val self = new Foo() - - val res4 = { - l // explicit chain method call - previously derivedSelect broke the type - .findVirtual(classOf[Foo], "neg", methodType(classOf[Int], classOf[Int])) - .invokeExact(self, 4): Int - } - assert(-4 == res4) diff --git a/tests/flexible-types/run/instanceof-nothing.scala b/tests/flexible-types/run/instanceof-nothing.scala deleted file mode 100644 index ef5fc4ede841..000000000000 --- a/tests/flexible-types/run/instanceof-nothing.scala +++ /dev/null @@ -1,26 +0,0 @@ -// Check that calling `asInstanceOf[Nothing]` throws a ClassCastException. -// In particular, the compiler needs access to the right method to throw -// the exception, and identifying the method uses some explicit nulls related -// logic (see ClassCastExceptionClass in Definitions.scala). - -object Test { - def main(args: Array[String]): Unit = { - val x: String = "hello" - try { - val y: Nothing = x.asInstanceOf[Nothing] - assert(false) - } catch { - case e: ClassCastException => - // ok - } - - val n: Null = null - try { - val y: Nothing = n.asInstanceOf[Nothing] - assert(false) - } catch { - case e: ClassCastException => - // ok - } - } -} diff --git a/tests/flexible-types/run/interop-unsound-src/J.java b/tests/flexible-types/run/interop-unsound-src/J.java deleted file mode 100644 index e06b22c3bae2..000000000000 --- a/tests/flexible-types/run/interop-unsound-src/J.java +++ /dev/null @@ -1,17 +0,0 @@ - -class JavaBox { - T contents; - - JavaBox(T contents) { this.contents = contents; } -} - -class Forwarder { - - static > void putInJavaBox(T box, String s) { - box.contents = s; - } - - static > void putInScalaBox(T box, String s) { - box.setContents(s); - } -} diff --git a/tests/flexible-types/run/interop-unsound-src/S.scala b/tests/flexible-types/run/interop-unsound-src/S.scala deleted file mode 100644 index 2e5eca0c1e5b..000000000000 --- a/tests/flexible-types/run/interop-unsound-src/S.scala +++ /dev/null @@ -1,33 +0,0 @@ -// An example that shows that the nullability transform is unsound. - -class ScalaBox[T](init: T) { - var contents: T = init - - def setContents(c: T): Unit = { - contents = c - } -} - -object Test { - - def main(args: Array[String]): Unit = { - val jb: JavaBox[String] = new JavaBox("hello") - val sb: ScalaBox[String] = ScalaBox("world") - - Forwarder.putInJavaBox(jb, null) // not unsound, becase JavaBox is java-defined - // so the contents fields will have a nullable - // type - - Forwarder.putInScalaBox(sb, null) // this is unsound, because ScalaBox - // should contain only Strings, but we added - // a null - - try { - sb.contents.length - assert(false) - } catch { - case ex: NullPointerException => - // expected - } - } -}