diff options
author | Paul Phillips <paulp@improving.org> | 2009-08-23 19:10:07 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-08-23 19:10:07 +0000 |
commit | 0f7296a008e0e4090e69b489c23a492df26fd4f6 (patch) | |
tree | f1eec61e91fb4ca4c71494cf0f57a1130e5c6f4c | |
parent | affff809b09e3d23a2625080db3b0c7d9d8b1e0e (diff) | |
download | scala-0f7296a008e0e4090e69b489c23a492df26fd4f6.tar.gz scala-0f7296a008e0e4090e69b489c23a492df26fd4f6.tar.bz2 scala-0f7296a008e0e4090e69b489c23a492df26fd4f6.zip |
Generalized pattern matcher generated null test.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeDSL.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 3 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala index 253994744b..6d1914f88b 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala @@ -23,6 +23,15 @@ trait TreeDSL { // clarity aliases type TreeFunction1 = Tree => Tree type TreeFunction2 = (Tree, Tree) => Tree + type BooleanTreeFunction2 = (Tree, Tree) => Boolean + + // Add a null check to a Tree => Tree function + // (this assumes your result Tree is representing a Boolean expression) + def nullSafe[T](f: TreeFunction1): TreeFunction1 = + tree => (tree OBJ_!= NULL) AND f(tree) + + // XXX these two are in scala.PartialFunction now, just have to + // settle on the final names. // Create a conditional based on a partial function - for values not defined // on the partial, it is false. @@ -102,6 +111,7 @@ trait TreeDSL { def APPLY(params: Tree*) = Apply(target, params.toList) def APPLY(params: List[Tree]) = Apply(target, params) def MATCH(cases: CaseDef*) = Match(target, cases.toList) + def DOT(member: Name) = SelectStart(Select(target, member)) def DOT(sym: Symbol) = SelectStart(Select(target, sym)) diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 315ce16562..e02d13ff23 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -788,8 +788,9 @@ trait ParallelMatching extends ast.TreeDSL { protected def lengthCheck(tree: Tree, len: Int, op: TreeFunction2) = { def compareOp = head.tpe member nme.lengthCompare // symbol for "lengthCompare" method + def cmpFunction(t1: Tree) = op((t1.duplicate DOT compareOp)(LIT(len)), ZERO) // first ascertain lhs is not null: bug #2241 - typer typed((tree OBJ_!= NULL) AND op((tree.duplicate DOT compareOp)(LIT(len)), ZERO)) + typer typed nullSafe(cmpFunction _)(tree) } // precondition for matching: sequence is exactly length of arg |