Aladdin - Scala Bugtracking
[#930] project: compiler priority: low category: feature
submitter assigned to status date submitted
Sean Martin fixed 2007-02-01 10:24:43.0
subject run-time type of null not matching?
code
package test;

object Test {
  def main(args : Array[String]) : Unit = {
    val x : Null = null;
    Console.println(x match {
    case that : Null if that eq null => true;
    case _ => false;
  });
  }
}
what happened
Program runs, prints "false"
what expected Should print true.
[back to overview]
Changes of this bug report
Burak  edited on  2007-02-01 16:01:47.0
for the record, behavior is according to spec.
Martin says the pattern is redundant, and asks me to detect this, but in fact it is not: it has a guard.
So I mark this as "feature".
Burak  edited on  2007-02-01 16:02:15.0
Martin  edited on  2007-02-01 17:10:14.0
I claim it is redundant: x: Null is never true. Adding a guard does not change this.
Burak  edited on  2007-02-01 17:24:31.0
would it not be better to flag it as an ill-typed pattern, outlawing it all together? The "redundancy" you mention depends on the type of the pattern. There is no precedence for doing anything to patterns that are of some special type (whereas for all types, if static type coincides with type to be tested, then the type test is omitted and we just emit a null check).
Martin  edited on  2007-02-03 10:52:21.0
Martin  edited on  2007-03-05 23:56:04.0
Program is now rejected statically with:
bug930.scala:7: error: this type cannot be used in a type pattern
    case that : Null if that eq null => true;
                ^