File tree Expand file tree Collapse file tree 3 files changed +7
-12
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -771,15 +771,11 @@ class Definitions {
771
771
}
772
772
773
773
def isProductSubType (tp : Type )(implicit ctx : Context ) =
774
- (tp derivesFrom ProductType .symbol) && tp.baseClasses.exists(isProductClass)
774
+ (tp.derivesFrom(ProductType .symbol) && tp.baseClasses.exists(isProductClass)) ||
775
+ tp.derivesFrom(NameBasedPatternType .symbol)
775
776
776
777
def productArity (tp : Type )(implicit ctx : Context ) =
777
- if (tp derivesFrom ProductType .symbol)
778
- tp.baseClasses.find(isProductClass) match {
779
- case Some (prod) => prod.typeParams.length
780
- case None => - 1
781
- }
782
- else - 1
778
+ if (isProductSubType(tp)) typer.Applications .productSelectorTypes(tp).size else - 1
783
779
784
780
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN ? */
785
781
def isFunctionType (tp : Type )(implicit ctx : Context ) = {
Original file line number Diff line number Diff line change @@ -52,8 +52,8 @@ object Applications {
52
52
* This is the case of `tp` is a subtype of the Product<numArgs> class.
53
53
*/
54
54
def isProductMatch (tp : Type , numArgs : Int )(implicit ctx : Context ) =
55
- 0 <= numArgs && numArgs <= Definitions . MaxTupleArity &&
56
- tp.derivesFrom(defn. ProductNType (numArgs).typeSymbol)
55
+ 0 <= numArgs && defn.isProductSubType(tp) &&
56
+ productSelectorTypes(tp).size == numArgs
57
57
58
58
/** Does `tp` fit the "get match" conditions as an unapply result type?
59
59
* This is the case of `tp` has a `get` member as well as a
Original file line number Diff line number Diff line change @@ -746,10 +746,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
746
746
747
747
/** Is `formal` a product type which is elementwise compatible with `params`? */
748
748
def ptIsCorrectProduct (formal : Type ) = {
749
- val pclass = defn.ProductNType (params.length).symbol
750
749
isFullyDefined(formal, ForceDegree .noBottom) &&
751
- formal.derivesFrom(pclass) &&
752
- formal.baseArgTypes(pclass ).corresponds(params) {
750
+ defn.isProductSubType(formal) &&
751
+ Applications .productSelectorTypes(formal ).corresponds(params) {
753
752
(argType, param) =>
754
753
param.tpt.isEmpty || argType <:< typedAheadType(param.tpt).tpe
755
754
}
You can’t perform that action at this time.
0 commit comments