@@ -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