title: Inconsistent behaviour with Null Type in Scala
body: <p>According to the <a href="http://www.scala-lang.org/api/current/index.html#scala.Null" rel="nofollow">scala docs</a>:</p>
  
  <blockquote>
    <p>Null is a subtype of all reference types;</p>
  </blockquote>
  
  <p>So in theory, in this example we can assume <code>Null</code> is a subtype of <code>Foo</code> (a reference type) and that we should be able to attempt to call the <code>bar</code> method on an instance of type <code>Null</code>. In practice we can't and the code snippet fails at compile time with the error <code>value bar is not a member of Null</code>.</p>
  
  <hr>
  
  <pre><code>case class Foo(bar: String)
  
  val n: Null = null
  n.bar
  </code></pre>
  
  <p><a href="http://www.scalakata.com/524e82fbe4b0b1a1c4da95e3" rel="nofollow">Try it</a></p>
  
  <hr>
  
  <p>I think it makes sense that we catch this at compile time because as the scala docs also <a href="http://www.scala-lang.org/api/current/index.html#scala.Null" rel="nofollow">say</a> <code>[Null's] only instance is the null reference</code>, however I think a better error message would be <code>Calling bar on type Null can only result in a NullPointerException</code>.</p>
  
  <p>My question is regarding the following code snippet, which doesn't fail at compile time and instead fails at runtime with a <code>NullPointerException</code></p>
  
  <hr>
  
  <pre><code>val n: Null = null
  n.toString
  </code></pre>
  
  <p><a href="http://www.scalakata.com/524e8c46e4b0b1a1c4da95e5" rel="nofollow">Try it</a></p>
  
  <hr>
  
  <p>I am assuming this is because the Null type doesn't truly subclass every other reference type and only subclasses <code>AnyRef</code>, but is there any reason why this shouldn't throw a compile time error (or at least warning) that this code can only result in a <code>NullPointerException</code>? Is it deliberate that calling <code>null.bar</code> and <code>null.toString</code> behave differently?</p>