summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-12-21 14:39:34 -0800
committerAdriaan Moors <adriaan@lightbend.com>2016-12-21 16:08:29 -0800
commit014ebc4606b6c3ecd305cee672f9ca734df77079 (patch)
tree0348e9971ddc867e8b9016ddaa3b71ceeb7903dc /src
parent23548c4301e48cb69f05cd01ceba418dc9c36d6c (diff)
downloadscala-014ebc4606b6c3ecd305cee672f9ca734df77079.tar.gz
scala-014ebc4606b6c3ecd305cee672f9ca734df77079.tar.bz2
scala-014ebc4606b6c3ecd305cee672f9ca734df77079.zip
Small cleanups to pattern matcher
While investigating https://github.com/scala/scala-dev/issues/251
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala30
2 files changed, 19 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
index cca8d2dbb8..f827043094 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
@@ -116,8 +116,8 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
case _ =>
}
- debug.patmat("sharedPrefix: "+ sharedPrefix)
- debug.patmat("suffix: "+ sharedPrefix)
+ debug.patmat(s"sharedPrefix: $sharedPrefix")
+ debug.patmat(s"suffix: $suffix")
// if the shared prefix contains interesting conditions (!= True)
// and the last of such interesting shared conditions reuses another treemaker's test
// replace the whole sharedPrefix by a ReusingCondTreeMaker
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
index a2afb76b0e..bf3bc6b26e 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -110,25 +110,29 @@ trait MatchTranslation {
// example check: List[Int] <:< ::[Int]
private def extractorStep(): TranslationStep = {
- def paramType = extractor.aligner.wholeType
import extractor.treeMaker
- // chain a type-testing extractor before the actual extractor call
- // it tests the type, checks the outer pointer and casts to the expected type
- // TODO: the outer check is mandated by the spec for case classes, but we do it for user-defined unapplies as well [SPEC]
- // (the prefix of the argument passed to the unapply must equal the prefix of the type of the binder)
- lazy val typeTest = TypeTestTreeMaker(binder, binder, paramType, paramType)(pos, extractorArgTypeTest = true)
- // check whether typetest implies binder is not null,
- // even though the eventual null check will be on typeTest.nextBinder
- // it'll be equal to binder casted to paramType anyway (and the type test is on binder)
- def extraction: TreeMaker = treeMaker(typeTest.nextBinder, typeTest impliesBinderNonNull binder, pos)
// paramType = the type expected by the unapply
// TODO: paramType may contain unbound type params (run/t2800, run/t3530)
- val makers = (
+ val makers = {
+ val paramType = extractor.aligner.wholeType
// Statically conforms to paramType
if (this ensureConformsTo paramType) treeMaker(binder, false, pos) :: Nil
- else typeTest :: extraction :: Nil
- )
+ else {
+ // chain a type-testing extractor before the actual extractor call
+ // it tests the type, checks the outer pointer and casts to the expected type
+ // TODO: the outer check is mandated by the spec for case classes, but we do it for user-defined unapplies as well [SPEC]
+ // (the prefix of the argument passed to the unapply must equal the prefix of the type of the binder)
+ val typeTest = TypeTestTreeMaker(binder, binder, paramType, paramType)(pos, extractorArgTypeTest = true)
+ val binderKnownNonNull = typeTest impliesBinderNonNull binder
+
+ // check whether typetest implies binder is not null,
+ // even though the eventual null check will be on typeTest.nextBinder
+ // it'll be equal to binder casted to paramType anyway (and the type test is on binder)
+ typeTest :: treeMaker(typeTest.nextBinder, binderKnownNonNull, pos) :: Nil
+ }
+ }
+
step(makers: _*)(extractor.subBoundTrees: _*)
}