summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorSeth Tisue <seth@tisue.net>2017-02-16 14:08:07 -0800
committerSeth Tisue <seth@tisue.net>2017-02-16 14:08:07 -0800
commit3fc5059a1e1f4c8946a76ae81112c9a0a91ddc86 (patch)
tree4105e9f48680020f7c2145d394dc2a89001069f7 /src/compiler
parente04e2818359c2504124e4d1ef776994a08734060 (diff)
parent014ebc4606b6c3ecd305cee672f9ca734df77079 (diff)
downloadscala-3fc5059a1e1f4c8946a76ae81112c9a0a91ddc86.tar.gz
scala-3fc5059a1e1f4c8946a76ae81112c9a0a91ddc86.tar.bz2
scala-3fc5059a1e1f4c8946a76ae81112c9a0a91ddc86.zip
Merge commit '014ebc4' into merge-2.11.x-to-2.12.x-20170214
Diffstat (limited to 'src/compiler')
-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 6fdaa79c10..dc0a457be7 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 5750f8f7e7..39971590c7 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -109,25 +109,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 (tpe <:< 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: _*)
}