Skip to content

Commit 0fa203f

Browse files
aherlihyWojciechMazur
authored andcommitted
Refactor out getOfGetMatch
[Cherry-picked 73da315]
1 parent 5b1dccf commit 0fa203f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,12 @@ object PatternMatcher {
343343
receiver.ensureConforms(defn.NonEmptyTupleTypeRef), // If scrutinee is a named tuple, cast to underlying tuple
344344
Literal(Constant(i)))
345345

346+
def getOfGetMatch(gm: Tree) = gm.select(nme.get, _.info.isParameterless)
346347
// Disable Scala2Unapply optimization if the argument is a named argument for a single-element named tuple to
347348
// enable selecting the field. See i23131.scala for test cases.
348349
val wasUnaryNamedTupleSelectArgForNamedTuple =
349350
args.length == 1 && args.head.removeAttachment(FirstTransform.WasNamedArg).isDefined &&
350-
isGetMatch(unappType) && unapp.select(nme.get, _.info.isParameterless).tpe.widenDealias.isNamedTupleType
351+
isGetMatch(unappType) && getOfGetMatch(unapp).tpe.widenDealias.isNamedTupleType
351352
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length && !wasUnaryNamedTupleSelectArgForNamedTuple)
352353
def tupleSel(sym: Symbol) =
353354
// If scrutinee is a named tuple, cast to underlying tuple, so that we can
@@ -381,7 +382,7 @@ object PatternMatcher {
381382
else {
382383
assert(isGetMatch(unappType))
383384
val argsPlan = {
384-
val get = ref(unappResult).select(nme.get, _.info.isParameterless)
385+
val get = getOfGetMatch(ref(unappResult))
385386
val arity = productArity(get.tpe.stripNamedTuple, unapp.srcPos)
386387
if (isUnapplySeq)
387388
letAbstract(get) { getResult =>

0 commit comments

Comments
 (0)