Aladdin - Scala Bugtracking
[#499] project: nsc priority: low category: bug
submitter assigned to status date submitted
Lex Burak fixed 2005-11-25 15:42:01.0
subject pattern with null
code
// a case statement with null as one of the patterns

object Foo {
  def foo(arg:String):int = {
    arg match {
      case null => 0;
      case "hello" => 1;
      case _ => 2;
    }
  }
}
what happened
Exception in thread "main" java.lang.NullPointerException
	at scala.tools.nsc.matching.PatternNodes$PatternNode$class.subsumes(PatternNodes.scala:161)
	at scala.tools.nsc.matching.PatternNodes$PatternNode$class.isSameAs(PatternNodes.scala:129)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$class.enter1(PatternMatchers.scala:439)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$class.enter(PatternMatchers.scala:101)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$class.scala$tools$nsc$matching$PatternMatchers$Patte\
rnMatcher$access$scala$tools$nsc$matching$PatternMatchers$PatternMatcher$enter(PatternMatchers.scala:18)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$$anon$1.apply(PatternMatchers.scala:91)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$$anon$1.apply(PatternMatchers.scala:91)
	at scala.List$class.scala$List$loop$5(List.scala:577)
	at scala.List$class.foreach(List.scala:579)
	at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$class.construct(PatternMatchers.scala:91)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.handle(TransMatcher.scala:246)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.transform(TransMatcher.scala:273)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$30.apply(Trees.scala:835)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$30.apply(Trees.scala:834)
	at scala.tools.nsc.ast.Trees$Transformer$class.atOwner(Trees.scala:936)
	at scala.tools.nsc.ast.Trees$Transformer$class.transform(Trees.scala:833)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.transform(TransMatcher.scala:279)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$21.apply(Trees.scala:930)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$21.apply(Trees.scala:928)
	at scala.List$.mapConserve(List.scala:227)
	at scala.List$.mapConserve(List.scala:229)
	at scala.tools.nsc.ast.Trees$Transformer$class.transformStats(Trees.scala:928)
	at scala.tools.nsc.ast.Trees$Transformer$class.transform(Trees.scala:854)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.transform(TransMatcher.scala:279)
	at scala.tools.nsc.ast.Trees$Transformer$class.transformTemplate(Trees.scala:916)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$27.apply(Trees.scala:822)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$27.apply(Trees.scala:822)
	at scala.tools.nsc.ast.Trees$Transformer$class.atOwner(Trees.scala:936)
	at scala.tools.nsc.ast.Trees$Transformer$class.transform(Trees.scala:821)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.transform(TransMatcher.scala:279)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$21.apply(Trees.scala:930)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$21.apply(Trees.scala:928)
	at scala.List$.mapConserve(List.scala:227)
	at scala.tools.nsc.ast.Trees$Transformer$class.transformStats(Trees.scala:928)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$26.apply(Trees.scala:818)
	at scala.tools.nsc.ast.Trees$Transformer$$anon$26.apply(Trees.scala:818)
	at scala.tools.nsc.ast.Trees$Transformer$class.atOwner(Trees.scala:936)
	at scala.tools.nsc.ast.Trees$Transformer$class.transform(Trees.scala:817)
	at scala.tools.nsc.matching.TransMatcher$TransMatch$class.transform(TransMatcher.scala:279)
	at scala.tools.nsc.ast.Trees$Transformer$class.transformUnit(Trees.scala:931)
	at scala.tools.nsc.transform.Transform$Phase$class.apply(Transform.scala:22)
	at scala.tools.nsc.Global$GlobalPhase$class.applyPhase(Global.scala:170)
	at scala.tools.nsc.Global$GlobalPhase$$anon$7.apply(Global.scala:162)
	at scala.tools.nsc.Global$GlobalPhase$$anon$7.apply(Global.scala:162)
	at scala.Iterator$class.foreach(Iterator.scala:262)
	at scala.tools.nsc.Global$GlobalPhase$class.run(Global.scala:162)
	at scala.tools.nsc.Global$Run$class.compileSources(Global.scala:339)
	at scala.tools.nsc.Global$Run$$anon$20.apply(Global.scala:397)
	at scala.tools.nsc.Global$Run$$anon$20.apply(Global.scala:397)
	at scala.runtime.ScalaRunTime$$anon$0.run(ScalaRunTime.scala:34)
	at scala.runtime.RunTime.tryCatch(RunTime.java:79)
	at scala.runtime.ScalaRunTime$$anon$0.(ScalaRunTime.scala:32)
	at scala.runtime.ScalaRunTime$.Try(ScalaRunTime.scala:30)
	at scala.tools.nsc.Global$Run$class.compile(Global.scala:396)
	at scala.tools.nsc.Main$$anon$4.apply(Main.scala:55)
	at scala.tools.nsc.Main$$anon$4.apply(Main.scala:48)
	at scala.runtime.ScalaRunTime$$anon$0.run(ScalaRunTime.scala:34)
	at scala.runtime.RunTime.tryCatch(RunTime.java:79)
	at scala.runtime.ScalaRunTime$$anon$0.(ScalaRunTime.scala:32)
	at scala.runtime.ScalaRunTime$.Try(ScalaRunTime.scala:30)
	at scala.tools.nsc.Main$.process(Main.scala:48)
	at scala.tools.nsc.Main$.main(Main.scala:67)
	at scala.tools.nsc.Main.main(Main.scala:66)
what expected A clean compile. Or if not that, an error message instead of a crash. Commenting out the "case null" line results in a clean compile.
[back to overview]
Changes of this bug report
Burak  edited on  2005-11-25 17:40:39.0
just required changing "x.equals(y)" into "x == y".
Burak  edited on  2005-11-25 17:58:34.0
(in my PatternNodes::subsumes function, of course :-)
Burak  edited on  2005-12-15 10:11:09.0
assigned to myself, easier for searching