Skip to content

Commit a792788

Browse files
Move isProductSubType to Applications & rename to canProductMatch
1 parent 3d92946 commit a792788

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,6 @@ class Definitions {
849849
def isTupleType(tp: Type)(implicit ctx: Context) =
850850
tp.derivesFrom(TupleType.symbol)
851851

852-
def isProductSubType(tp: Type)(implicit ctx: Context) =
853-
Applications.extractorMemberType(tp, nme._1).exists
854-
855852
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN? */
856853
def isFunctionType(tp: Type)(implicit ctx: Context) = {
857854
val arity = functionArity(tp)

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
14041404
protected def seqTree(binder: Symbol) = tupleSel(binder)(firstIndexingBinder + 1)
14051405
protected def tupleSel(binder: Symbol)(i: Int): Tree = {
14061406
val accessors =
1407-
if (defn.isProductSubType(binder.info))
1407+
if (Applications.canProductMatch(binder.info))
14081408
productSelectors(binder.info)
14091409
else binder.caseAccessors
14101410
val res =

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ object Applications {
4747
ref.info.widenExpr.dealias
4848
}
4949

50+
def canProductMatch(tp: Type)(implicit ctx: Context) =
51+
extractorMemberType(tp, nme._1).exists
52+
5053
/** Does `tp` fit the "product match" conditions as an unapply result type
5154
* for a pattern with `numArgs` subpatterns?
5255
* This is the case of `tp` has members `_1` to `_N` where `N == numArgs`.
5356
*/
5457
def isProductMatch(tp: Type, numArgs: Int)(implicit ctx: Context) =
55-
numArgs > 0 && defn.isProductSubType(tp) &&
56-
productSelectorTypes(tp).size == numArgs
58+
numArgs > 0 && productArity(tp) == numArgs
5759

5860
/** Does `tp` fit the "get match" conditions as an unapply result type?
5961
* This is the case of `tp` has a `get` member as well as a
@@ -69,7 +71,7 @@ object Applications {
6971
}
7072

7173
def productArity(tp: Type)(implicit ctx: Context) =
72-
if (defn.isProductSubType(tp)) productSelectorTypes(tp).size else -1
74+
if (canProductMatch(tp)) productSelectorTypes(tp).size else -1
7375

7476
def productSelectors(tp: Type)(implicit ctx: Context): List[Symbol] = {
7577
val sels = for (n <- Iterator.from(0)) yield tp.member(nme.selectorName(n)).symbol
@@ -111,7 +113,7 @@ object Applications {
111113
getUnapplySelectors(getTp, args, pos)
112114
else if (unapplyResult isRef defn.BooleanClass)
113115
Nil
114-
else if (defn.isProductSubType(unapplyResult))
116+
else if (canProductMatch(unapplyResult))
115117
productSelectorTypes(unapplyResult)
116118
// this will cause a "wrong number of arguments in pattern" error later on,
117119
// which is better than the message in `fail`.

0 commit comments

Comments
 (0)