diff --git a/compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala b/compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala index a72943f2128f..d4aea805b0fe 100644 --- a/compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala +++ b/compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala @@ -107,10 +107,13 @@ object ImplicitNullInterop { case tp: TypeRef if !tp.hasSimpleKind // We don't modify value types because they're non-nullable even in Java. || tp.symbol.isValueClass + || tp.isRef(defn.NullClass) + || tp.isRef(defn.NothingClass) // We don't modify unit types. || tp.isRef(defn.UnitClass) // We don't modify `Any` because it's already nullable. || tp.isRef(defn.AnyClass) => false + case tp: TypeParamRef if !tp.hasSimpleKind => false case _ => true // We don't nullify Java varargs at the top level. diff --git a/tests/explicit-nulls/flexible-unpickle/Flexible_2.scala b/tests/explicit-nulls/flexible-unpickle/Flexible_2.scala index 20448d31c3aa..7fc56d1cc462 100644 --- a/tests/explicit-nulls/flexible-unpickle/Flexible_2.scala +++ b/tests/explicit-nulls/flexible-unpickle/Flexible_2.scala @@ -1,6 +1,6 @@ import unsafeNulls.Foo.* import unsafeNulls.Unsafe_1 -import unsafeNulls.{A, B, C, F, G, H, I, J, L, M, S, T, U, expects} +import unsafeNulls.{A, B, C, F, G, H, I, J, L, M, N, S, T, U, expects} import scala.reflect.Selectable.reflectiveSelectable import scala.quoted.* @@ -100,6 +100,11 @@ def Flexible_2() = val m: String = M.test(null) + // i23911 + val n1: List[Map[String, Int]] = ??? + val n2 = new N[List]() + val n3 = n2.accept[Any](n1) + // i23845 transparent inline def typeName[A]: String = ${typeNameMacro[A]} @@ -109,3 +114,4 @@ def Flexible_2() = implicit val givenS: S[A] = ??? expects(alphaTypeNameMacro[A]) } + diff --git a/tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala b/tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala index 6bec3dabf302..7f118d7805ad 100644 --- a/tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala +++ b/tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala @@ -73,6 +73,11 @@ object M { def test(input: => String): String = "foo " + input } + +class N[F[_]] { + def accept[A](arg: F[A]): Nothing = ??? +} + class S[X] object S { def show[X] = "dummyStr" } class T