Skip to content

Commit c7f8241

Browse files
committed
Rename productArity in pattern matcher to prodArity
productArity is a method defined in ProductN which is inherited from case classes. It is possible that it will be usewd in the implementation of pattern matching in the future. The previous implementation used the same name to mean something else: Not the arity of the case class itself but the arity of the pattern/type it represented. Renaming to prodArity avoids the confusion.
1 parent b7e547c commit c7f8241

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
13761376

13771377
def subPatTypes: List[Type] = typedPatterns map (_.tpe)
13781378

1379-
// there are `productArity` non-seq elements in the tuple.
1380-
protected def firstIndexingBinder = productArity
1379+
// there are `prodArity` non-seq elements in the tuple.
1380+
protected def firstIndexingBinder = prodArity
13811381
protected def expectedLength = elementArity
13821382
protected def lastIndexingBinder = totalArity - starArity - 1
13831383

@@ -1535,7 +1535,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
15351535
// the trees that select the subpatterns on the extractor's result, referenced by `binder`
15361536
// require (totalArity > 0 && (!lastIsStar || isSeq))
15371537
protected def subPatRefs(binder: Symbol, subpatBinders: List[Symbol], binderTypeTested: Type): List[Tree] = {
1538-
if(aligner.isSingle && aligner.extractor.productArity == 1 && defn.isTupleType(binder.info)) {
1538+
if(aligner.isSingle && aligner.extractor.prodArity == 1 && defn.isTupleType(binder.info)) {
15391539
// special case for extractor
15401540
// comparing with scalac additional assertions added
15411541
val subpw = subpatBinders.head.info.widen
@@ -1577,13 +1577,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
15771577
*
15781578
* Here Pm/Fi is the last pattern to match the fixed arity section.
15791579
*
1580-
* productArity: the value of i, i.e. the number of non-sequence types in the extractor
1580+
* prodArity: the value of i, i.e. the number of non-sequence types in the extractor
15811581
* nonStarArity: the value of j, i.e. the number of non-star patterns in the case definition
15821582
* elementArity: j - i, i.e. the number of non-star patterns which must match sequence elements
15831583
* starArity: 1 or 0 based on whether there is a star (sequence-absorbing) pattern
15841584
* totalArity: nonStarArity + starArity, i.e. the number of patterns in the case definition
15851585
*
1586-
* Note that productArity is a function only of the extractor, and
1586+
* Note that prodArity is a function only of the extractor, and
15871587
* nonStar/star/totalArity are all functions of the patterns. The key
15881588
* value for aligning and typing the patterns is elementArity, as it
15891589
* is derived from both sets of information.
@@ -1651,7 +1651,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
16511651
final case class Extractor(whole: Type, fixed: List[Type], repeated: Repeated) {
16521652
require(whole != NoType, s"expandTypes($whole, $fixed, $repeated)")
16531653

1654-
def productArity = fixed.length
1654+
def prodArity = fixed.length
16551655
def hasSeq = repeated.exists
16561656
def elementType = repeated.elementType
16571657
def sequenceType = repeated.sequenceType
@@ -1681,8 +1681,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
16811681
* < 0: There are more products than patterns: compile time error.
16821682
*/
16831683
final case class Aligned(patterns: Patterns, extractor: Extractor) {
1684-
def elementArity = patterns.nonStarArity - productArity
1685-
def productArity = extractor.productArity
1684+
def elementArity = patterns.nonStarArity - prodArity
1685+
def prodArity = extractor.prodArity
16861686
def starArity = patterns.starArity
16871687
def totalArity = patterns.totalArity
16881688

@@ -1693,15 +1693,15 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
16931693
def typedNonStarPatterns = products ::: elements
16941694
def typedPatterns = typedNonStarPatterns ::: stars
16951695

1696-
def isBool = !isSeq && productArity == 0
1696+
def isBool = !isSeq && prodArity == 0
16971697
def isSingle = !isSeq && totalArity == 1
16981698
def isStar = patterns.hasStar
16991699
def isSeq = extractor.hasSeq
17001700

17011701
private def typedAsElement(pat: Pattern) = TypedPat(pat, extractor.elementType)
17021702
private def typedAsSequence(pat: Pattern) = TypedPat(pat, extractor.sequenceType)
1703-
private def productPats = patterns.fixed take productArity
1704-
private def elementPats = patterns.fixed drop productArity
1703+
private def productPats = patterns.fixed take prodArity
1704+
private def elementPats = patterns.fixed drop prodArity
17051705
private def products = (productPats, productTypes).zipped map TypedPat
17061706
private def elements = elementPats map typedAsElement
17071707
private def stars = patterns.starPatterns map typedAsSequence
@@ -1710,7 +1710,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
17101710
|Aligned {
17111711
| patterns $patterns
17121712
| extractor $extractor
1713-
| arities $productArity/$elementArity/$starArity // product/element/star
1713+
| arities $prodArity/$elementArity/$starArity // product/element/star
17141714
| typed ${typedPatterns mkString ", "}
17151715
|}""".stripMargin.trim
17161716
}
@@ -1826,7 +1826,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
18261826
def offering = extractor.offeringString
18271827
def symString = tree.symbol.showLocated
18281828
def offerString = if (extractor.isErroneous) "" else s" offering $offering"
1829-
def arityExpected = ( if (extractor.hasSeq) "at least " else "" ) + productArity
1829+
def arityExpected = ( if (extractor.hasSeq) "at least " else "" ) + prodArity
18301830

18311831
def err(msg: String) = ctx.error(msg, tree.pos)
18321832
def warn(msg: String) = ctx.warning(msg, tree.pos)
@@ -1871,12 +1871,12 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
18711871
* process, we will tuple the extractor before creation Aligned so that
18721872
* it contains known good values.
18731873
*/
1874-
def productArity = extractor.productArity
1874+
def prodArity = extractor.prodArity
18751875
def acceptMessage = if (extractor.isErroneous) "" else s" to hold ${extractor.offeringString}"
1876-
val requiresTupling = isUnapply && patterns.totalArity == 1 && productArity > 1
1876+
val requiresTupling = isUnapply && patterns.totalArity == 1 && prodArity > 1
18771877

18781878
//if (requiresTupling && effectivePatternArity(args) == 1)
1879-
// currentUnit.deprecationWarning(sel.pos, s"${sel.symbol.owner} expects $productArity patterns$acceptMessage but crushing into $productArity-tuple to fit single pattern (SI-6675)")
1879+
// currentUnit.deprecationWarning(sel.pos, s"${sel.symbol.owner} expects $prodArity patterns$acceptMessage but crushing into $prodArity-tuple to fit single pattern (SI-6675)")
18801880

18811881
val normalizedExtractor =
18821882
if (requiresTupling)

0 commit comments

Comments
 (0)