diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 3b2cb0db78c3..159102e1f875 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -912,7 +912,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling // scala.AnyRef [Scala 3: which scala.Null conforms to], the type denotes the set of values consisting // of null and the value denoted by p (i.e., the value v for which v eq p). [Otherwise,] the type // denotes the set consisting of only the value denoted by p. - isNullable(tp.underlying) && tp.isStable + !ctx.explicitNulls && isNullable(tp.underlying) && tp.isStable case tp: RefinedOrRecType => isNullable(tp.parent) case tp: AppliedType => isNullable(tp.tycon) case AndType(tp1, tp2) => isNullable(tp1) && isNullable(tp2) diff --git a/tests/explicit-nulls/neg/i17467.scala b/tests/explicit-nulls/neg/i17467.scala new file mode 100644 index 000000000000..b9220c8fece1 --- /dev/null +++ b/tests/explicit-nulls/neg/i17467.scala @@ -0,0 +1,10 @@ +object Test: + def test(): Unit = + val a1: String = "foo" + val a2: a1.type = null // error + + val b1: String | Null = "foo" + val b2: b1.type = null // error + summon[Null, b1.type] // error + end test +end Test