summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-03-06 13:26:30 +0000
committerPaul Phillips <paulp@improving.org>2010-03-06 13:26:30 +0000
commit68c2fff4c1103ded18788861f99654292c4e71d1 (patch)
treea8d81b829e7f6cce92fde969ae5da8485c144b27
parent8d59708911be076e227a046eb1dd14421e1a9cb7 (diff)
downloadscala-68c2fff4c1103ded18788861f99654292c4e71d1.tar.gz
scala-68c2fff4c1103ded18788861f99654292c4e71d1.tar.bz2
scala-68c2fff4c1103ded18788861f99654292c4e71d1.zip
Fixes for #3126.
null, and thrown MatchErrors don't NPE trying to stringify null. No review.
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala11
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala4
-rw-r--r--test/files/run/bug3126.scala9
4 files changed, 19 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index a788015262..fd13958053 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -88,6 +88,8 @@ trait TreeDSL {
def ANY_>= (other: Tree) = fn(target, nme.GE, other)
def ANY_<= (other: Tree) = fn(target, nme.LE, other)
def OBJ_!= (other: Tree) = fn(target, Object_ne, other)
+ def OBJ_EQ (other: Tree) = fn(target, nme.eq, other)
+ def OBJ_NE (other: Tree) = fn(target, nme.ne, other)
def INT_| (other: Tree) = fn(target, getMember(IntClass, nme.OR), other)
def INT_& (other: Tree) = fn(target, getMember(IntClass, nme.AND), other)
@@ -187,10 +189,11 @@ trait TreeDSL {
}
/** Top level accessible. */
- def THROW(sym: Symbol, msg: Tree = null) = {
- val arg: List[Tree] = if (msg == null) Nil else List(msg.TOSTRING())
- Throw(New(TypeTree(sym.tpe), List(arg)))
- }
+ def MATCHERROR(arg: Tree) = Throw(New(TypeTree(MatchErrorClass.tpe), List(List(arg))))
+ /** !!! should generalize null guard from match error here. */
+ def THROW(sym: Symbol): Throw = Throw(New(TypeTree(sym.tpe), List(Nil)))
+ def THROW(sym: Symbol, msg: Tree): Throw = Throw(New(TypeTree(sym.tpe), List(List(msg.TOSTRING()))))
+
def NEW(tpe: Tree, args: Tree*) = New(tpe, List(args.toList))
def NEW(sym: Symbol, args: Tree*) =
if (args.isEmpty) New(TypeTree(sym.tpe))
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index 5333734afa..be455b00b0 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -44,7 +44,7 @@ trait TransMatcher extends ast.TreeDSL {
{
import context._
- def matchError(obj: Tree) = atPos(selector.pos)(THROW(MatchErrorClass, obj))
+ def matchError(obj: Tree) = atPos(selector.pos)(MATCHERROR(obj))
def caseIsOk(c: CaseDef) = cond(c.pat) { case _: Apply | Ident(nme.WILDCARD) => true }
def rootTypes = selector.tpe.typeArgs
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index 3898e46c0b..5b3ca89e84 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -171,10 +171,10 @@ trait Unapplies extends ast.TreeDSL
case _ => nme.unapply
}
val cparams = List(ValDef(Modifiers(PARAM | SYNTHETIC), paramName, classType(cdef, tparams), EmptyTree))
+ val body = nullSafe({ case Ident(x) => caseClassUnapplyReturnValue(x, cdef.symbol) }, MATCHERROR(NULL))(Ident(paramName))
atPos(cdef.pos.focus)(
- DefDef(caseMods, method, tparams, List(cparams), TypeTree(),
- caseClassUnapplyReturnValue(paramName, cdef.symbol))
+ DefDef(caseMods, method, tparams, List(cparams), TypeTree(), body)
)
}
diff --git a/test/files/run/bug3126.scala b/test/files/run/bug3126.scala
new file mode 100644
index 0000000000..36322bf896
--- /dev/null
+++ b/test/files/run/bug3126.scala
@@ -0,0 +1,9 @@
+object Test {
+ case class C(x: Int)
+ val v: Some[Int] = null
+
+ def main(args: Array[String]): Unit = {
+ try C.unapply(null) catch { case _: MatchError => }
+ try v match { case Some(1) => } catch { case _: MatchError => }
+ }
+}