From 2cf278b25baf138c0a9775bcbe7bc97b4b548139 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Thu, 19 Oct 2006 12:36:19 +0000 Subject: fix 781, nullpointerexcs in matcherror --- src/compiler/scala/tools/nsc/matching/PatternMatchers.scala | 6 ++++-- src/library/scala/MatchError.scala | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala index 27c5792069..145190f1ed 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala @@ -366,7 +366,9 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes) { //Console.println("tree.getClass() "+tree.getClass()); tree match { case Bind(name, Typed(Ident( nme.WILDCARD ), tpe)) => // x@_:Type - if (isSubType(header.getTpe(),tpe.tpe)) { + if (false && isSubType(header.getTpe(),tpe.tpe)) { + // this optimization is not correct, because + // null.isInstanceOf will return false val node = pDefaultPat(tree.pos, tpe.tpe) env.newBoundVar(tree.symbol, tree.tpe, header.selector) node @@ -1002,7 +1004,7 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes) { ); // forward jump if (guard(i) != EmptyTree) res0 = And(guard(i), res0); - res = Or(Block(ts.toList, res0), res); + res = Or(squeezedBlock(ts.toList, res0), res); i = i - 1 } if (_b.or != null) diff --git a/src/library/scala/MatchError.scala b/src/library/scala/MatchError.scala index a26c5087ce..6ef969b97c 100644 --- a/src/library/scala/MatchError.scala +++ b/src/library/scala/MatchError.scala @@ -23,13 +23,16 @@ import Predef._ */ object MatchError { + def string(obj: Any) = + if(obj != null) obj.toString() else "null" + // todo: change pattern matcher so that dummy type parameter T can be removed. def fail[T](source: String, line: Int): Nothing = throw new MatchError(source, line) def report(source: String, line: Int, obj: Any) = try { - throw new MatchError(source, line, obj.toString()) + throw new MatchError(source, line, string(obj)) } catch { case e: MatchError => throw e case e: Throwable => throw new MatchError(source, line) @@ -43,6 +46,6 @@ final class MatchError(msg: String) extends Error(msg) { def this(source: String, line: Int, obj: String) = this("for object " + obj + " in '" + source + "' at line " + line) - def this(ob: Any) = - this(ob.toString()) + def this(obj: Any) = + this(MatchError.string(obj)) } -- cgit v1.2.3