diff options
author | Olivier Blanvillain <olivier.blanvillain@gmail.com> | 2017-04-10 18:14:01 +0200 |
---|---|---|
committer | Olivier Blanvillain <olivier.blanvillain@gmail.com> | 2017-04-11 08:48:06 +0200 |
commit | 198b5cec531a8e0d6c121cc425e19a54b7818868 (patch) | |
tree | cedbb042b763d7184046fdd425b1ca9fc9591e9f /compiler/src/dotty/tools/dotc/typer/Applications.scala | |
parent | 5bf9d2b0046b60ae9fcdc218cd190e17023b4fae (diff) | |
download | dotty-198b5cec531a8e0d6c121cc425e19a54b7818868.tar.gz dotty-198b5cec531a8e0d6c121cc425e19a54b7818868.tar.bz2 dotty-198b5cec531a8e0d6c121cc425e19a54b7818868.zip |
Move isProductSubType to Applications & rename to canProductMatch
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Applications.scala | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 24d43858d..433a82d3e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -47,13 +47,15 @@ object Applications { ref.info.widenExpr.dealias } + def canProductMatch(tp: Type)(implicit ctx: Context) = + extractorMemberType(tp, nme._1).exists + /** Does `tp` fit the "product match" conditions as an unapply result type * for a pattern with `numArgs` subpatterns? * This is the case of `tp` has members `_1` to `_N` where `N == numArgs`. */ def isProductMatch(tp: Type, numArgs: Int)(implicit ctx: Context) = - numArgs > 0 && defn.isProductSubType(tp) && - productSelectorTypes(tp).size == numArgs + numArgs > 0 && productArity(tp) == numArgs /** Does `tp` fit the "get match" conditions as an unapply result type? * This is the case of `tp` has a `get` member as well as a @@ -69,7 +71,7 @@ object Applications { } def productArity(tp: Type)(implicit ctx: Context) = - if (defn.isProductSubType(tp)) productSelectorTypes(tp).size else -1 + if (canProductMatch(tp)) productSelectorTypes(tp).size else -1 def productSelectors(tp: Type)(implicit ctx: Context): List[Symbol] = { val sels = for (n <- Iterator.from(0)) yield tp.member(nme.selectorName(n)).symbol @@ -111,7 +113,7 @@ object Applications { getUnapplySelectors(getTp, args, pos) else if (unapplyResult isRef defn.BooleanClass) Nil - else if (defn.isProductSubType(unapplyResult)) + else if (canProductMatch(unapplyResult)) productSelectorTypes(unapplyResult) // this will cause a "wrong number of arguments in pattern" error later on, // which is better than the message in `fail`. |