Skip to content

Commit 198b5ce

Browse files
Move isProductSubType to Applications & rename to canProductMatch
1 parent 5bf9d2b commit 198b5ce

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,6 @@ class Definitions {
847847
TupleType(elems.size).appliedTo(elems)
848848
}
849849

850-
def isProductSubType(tp: Type)(implicit ctx: Context) =
851-
Applications.extractorMemberType(tp, nme._1).exists
852-
853850
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN? */
854851
def isFunctionType(tp: Type)(implicit ctx: Context) = {
855852
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
@@ -1408,7 +1408,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
14081408
protected def seqTree(binder: Symbol) = tupleSel(binder)(firstIndexingBinder + 1)
14091409
protected def tupleSel(binder: Symbol)(i: Int): Tree = {
14101410
val accessors =
1411-
if (defn.isProductSubType(binder.info))
1411+
if (Applications.canProductMatch(binder.info))
14121412
productSelectors(binder.info)
14131413
else binder.caseAccessors
14141414
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`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
762762
/** Is `formal` a product type which is elementwise compatible with `params`? */
763763
def ptIsCorrectProduct(formal: Type) = {
764764
isFullyDefined(formal, ForceDegree.noBottom) &&
765-
defn.isProductSubType(formal) &&
765+
Applications.canProductMatch(formal) &&
766766
Applications.productSelectorTypes(formal).corresponds(params) {
767767
(argType, param) =>
768768
param.tpt.isEmpty || argType <:< typedAheadType(param.tpt).tpe

0 commit comments

Comments
 (0)