Skip to content

Null subtyping is inconsistent #262

Closed
@smarter

Description

@smarter

I'm not sure what the semantics of Null should be exactly, but:

object O {
  // This compiles
  val a: { type T } = null;
  val b: Any { type T } = null;

  // This doesn't:
  // found   : Null
  // required: AnyRef{T}
  val c: AnyRef { type T } = null;
}

The problem is that the null subtyping check is done with:

(tp1.symbol eq NullClass) && tp2.dealias.typeSymbol.isNullableClass

But AnyRef is not a class (it's an alias of Object) so isNullableClass fails. What would be the most robust way to fix this?
By the way, should we remove NotNull? It's been deprecated in scalac already: scala/scala#2244
CC @odersky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions