diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
commit | b1553cb9c5894e2e91925a67afd2c986675e5c46 (patch) | |
tree | f9def6ae664f0df939a51b55c5283790b93a7c4d /compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala | |
parent | 9bf58090c704a59d8735874c565200758bcea666 (diff) | |
download | dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.gz dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.bz2 dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.zip |
Implement new rules for name-based pattern matching
This implements the rules laid down in #1805.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 1252781e8..181dfccd9 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -235,7 +235,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { // next: MatchMonad[U] // returns MatchMonad[U] def flatMap(prev: Tree, b: Symbol, next: Tree): Tree = { - if (isProductMatch(prev.tpe)) { + val resultArity = defn.productArity(b.info) + if (isProductMatch(prev.tpe, resultArity)) { val nullCheck: Tree = prev.select(defn.Object_ne).appliedTo(Literal(Constant(null))) ifThenElseZero( nullCheck, @@ -1429,7 +1430,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { def resultInMonad = if (aligner.isBool) defn.UnitType - else if (isProductMatch(resultType)) resultType + else if (isProductMatch(resultType, aligner.prodArity)) resultType else if (isGetMatch(resultType)) extractorMemberType(resultType, nme.get) else resultType @@ -1630,7 +1631,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { ref(binder) :: Nil } else if ((aligner.isSingle && aligner.extractor.prodArity == 1) && - !isProductMatch(binderTypeTested) && isGetMatch(binderTypeTested)) + !isProductMatch(binderTypeTested, aligner.prodArity) && isGetMatch(binderTypeTested)) List(ref(binder)) else subPatRefs(binder) @@ -1885,7 +1886,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { else if (result.classSymbol is Flags.CaseClass) result.decls.filter(x => x.is(Flags.CaseAccessor) && x.is(Flags.Method)).map(_.info).toList else result.select(nme.get) :: Nil )*/ - if (isProductMatch(resultType)) productSelectorTypes(resultType) + if (isProductMatch(resultType, args.length)) productSelectorTypes(resultType) else if (isGetMatch(resultType)) getUnapplySelectors(resultOfGet, args) else if (resultType isRef defn.BooleanClass) Nil else { |