Skip to content

Commit f3d887f

Browse files
committed
Merge pull request #277 from dotty-staging/change/drop-not-null
Change/drop not null
2 parents 1466e88 + 35ba97c commit f3d887f

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

src/dotty/tools/dotc/TypeErasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
253253
* - otherwise, if T is a type paramter coming from Java, []Object
254254
* - otherwise, Object
255255
* - For a term ref p.x, the type <noprefix> # x.
256-
* - For a typeref scala.Any, scala.AnyVal, scala.Singleon or scala.NotNull: |java.lang.Object|
256+
* - For a typeref scala.Any, scala.AnyVal or scala.Singleton: |java.lang.Object|
257257
* - For a typeref scala.Unit, |scala.runtime.BoxedUnit|.
258258
* - For a typeref P.C where C refers to a class, <noprefix> # C.
259259
* - For a typeref P.C where C refers to an alias type, the erasure of C's alias.
@@ -374,7 +374,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
374374

375375
private def normalizeClass(cls: ClassSymbol)(implicit ctx: Context): ClassSymbol = {
376376
if (cls.owner == defn.ScalaPackageClass) {
377-
if (cls == defn.AnyClass || cls == defn.AnyValClass || cls == defn.SingletonClass || cls == defn.NotNullClass)
377+
if (cls == defn.AnyClass || cls == defn.AnyValClass || cls == defn.SingletonClass)
378378
return defn.ObjectClass
379379
if (cls == defn.UnitClass)
380380
return defn.BoxedUnitClass

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class ScalaSettings extends Settings.SettingGroup {
140140
val Ybuilderdebug = ChoiceSetting("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none")
141141
val Yreifycopypaste = BooleanSetting("-Yreify-copypaste", "Dump the reified trees in copypasteable representation.")
142142
val Yreplsync = BooleanSetting("-Yrepl-sync", "Do not use asynchronous code for repl startup")
143-
val Ynotnull = BooleanSetting("-Ynotnull", "Enable (experimental and incomplete) scala.NotNull.")
144143
val YmethodInfer = BooleanSetting("-Yinfer-argument-types", "Infer types for arguments of overriden methods.")
145144
val etaExpandKeepsStar = BooleanSetting("-Yeta-expand-keeps-star", "Eta-expand varargs methods to T* rather than Seq[T]. This is a temporary option to ease transition.")
146145
val Yinvalidate = StringSetting("-Yinvalidate", "classpath-entry", "Invalidate classpath entry before run", "")

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ class Definitions {
177177
RootClass, nme.dummyApply, 1,
178178
pt => MethodType(List(FunctionType(Nil, PolyParam(pt, 0))), PolyParam(pt, 0)))
179179

180-
lazy val NotNullClass = ctx.requiredClass("scala.NotNull")
181-
182180
lazy val NothingClass: ClassSymbol = newCompleteClassSymbol(
183181
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
184182
lazy val NullClass: ClassSymbol = newCompleteClassSymbol(
@@ -348,7 +346,6 @@ class Definitions {
348346
def AnyValType: Type = AnyValClass.typeRef
349347
def ObjectType: Type = ObjectClass.typeRef
350348
def AnyRefType: Type = AnyRefAlias.typeRef
351-
def NotNullType: Type = NotNullClass.typeRef
352349
def NothingType: Type = NothingClass.typeRef
353350
def NullType: Type = NullClass.typeRef
354351
def SeqType: Type = SeqClass.typeRef

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ object SymDenotations {
466466

467467
/** Is this symbol a class references to which that are supertypes of null? */
468468
final def isNullableClass(implicit ctx: Context): Boolean =
469-
isNonValueClass && !(this is ModuleClass) // todo: check that class does not derive from NotNull?
469+
isNonValueClass && !(this is ModuleClass)
470470

471471
/** Is this definition accessible as a member of tree with type `pre`?
472472
* @param pre The type of the tree from which the selection is made

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ class TypeComparer(initctx: Context) extends DotClass {
648648
if (cls2.isClass) {
649649
val base = tp1.baseTypeRef(cls2)
650650
if (base.exists && (base ne tp1)) return isSubType(base, tp2)
651-
if ( cls2 == defn.SingletonClass && tp1.isStable
652-
|| cls2 == defn.NotNullClass && tp1.isNotNull) return true
651+
if (cls2 == defn.SingletonClass && tp1.isStable) return true
653652
}
654653
tryRebase3rd
655654
}
@@ -777,8 +776,13 @@ class TypeComparer(initctx: Context) extends DotClass {
777776
case TypeBounds(lo1, hi1) =>
778777
isSubType(hi1, tp2)
779778
case _ =>
779+
def isNullable(tp: Type): Boolean = tp.dealias match {
780+
case tp: TypeRef => tp.symbol.isNullableClass
781+
case RefinedType(parent, _) => isNullable(parent)
782+
case _ => false
783+
}
780784
(tp1.symbol eq NothingClass) && tp2.isInstanceOf[ValueType] ||
781-
(tp1.symbol eq NullClass) && tp2.dealias.typeSymbol.isNullableClass
785+
(tp1.symbol eq NullClass) && isNullable(tp2)
782786
}
783787
case tp1: SingletonType =>
784788
isNewSubType(tp1.underlying.widenExpr, tp2) || {

tests/pos/i262-null-subtyping.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object O {
2+
// This compiles
3+
val a: { type T } = null;
4+
val b: Any { type T } = null;
5+
6+
// This doesn't:
7+
// found : Null
8+
// required: AnyRef{T}
9+
val c: AnyRef { type T } = null;
10+
11+
class A
12+
class B
13+
14+
val d: A & B = null
15+
val e: A | B = null
16+
17+
val f: (A & B) { def toString: String } = null
18+
val g: (A | B) { def toString: String } = null
19+
}

0 commit comments

Comments
 (0)