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 | |
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')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Applications.scala | 10 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 |
2 files changed, 7 insertions, 5 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`. diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c86b15871..9494bf4eb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -762,7 +762,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit /** Is `formal` a product type which is elementwise compatible with `params`? */ def ptIsCorrectProduct(formal: Type) = { isFullyDefined(formal, ForceDegree.noBottom) && - defn.isProductSubType(formal) && + Applications.canProductMatch(formal) && Applications.productSelectorTypes(formal).corresponds(params) { (argType, param) => param.tpt.isEmpty || argType <:< typedAheadType(param.tpt).tpe |