Skip to content
Open
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
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/ImplicitNullInterop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also need to consider the following special classes: SingletonClass, AnyKindClass, FromJavaObjectSymbol, etc...

|| 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!tp.hasSimpleKind can be moved to the first if together with outermostLevelAlreadyNullable.

case _ => true

// We don't nullify Java varargs at the top level.
Expand Down
8 changes: 7 additions & 1 deletion tests/explicit-nulls/flexible-unpickle/Flexible_2.scala
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down Expand Up @@ -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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also test some type lambdas like [X] =>> R

// i23845
transparent inline def typeName[A]: String = ${typeNameMacro[A]}

Expand All @@ -109,3 +114,4 @@ def Flexible_2() =
implicit val givenS: S[A] = ???
expects(alphaTypeNameMacro[A])
}

5 changes: 5 additions & 0 deletions tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading