@@ -2044,12 +2044,16 @@ object desugar {
20442044 makeCaseLambda(CaseDef (gen.pat, EmptyTree , body) :: Nil , matchCheckMode)
20452045 }
20462046
2047- /** Does this pattern define any given bindings */
2048- def isGivenPattern (pat : Tree ): Boolean = pat.existsSubTree {
2047+ def hasGivenBind (pat : Tree ): Boolean = pat.existsSubTree {
20492048 case pat @ Bind (_, pat1) => pat.mods.is(Given )
20502049 case _ => false
20512050 }
20522051
2052+ /** Does this pattern define any given bindings */
2053+ def isNestedGivenPattern (pat : Tree ): Boolean = pat match
2054+ case pat @ Bind (_, pat1) => hasGivenBind(pat1)
2055+ case _ => hasGivenBind(pat)
2056+
20532057 /** If `pat` is not an Identifier, a Typed(Ident, _), or a Bind, wrap
20542058 * it in a Bind with a fresh name. Return the transformed pattern, and the identifier
20552059 * that refers to the bound variable for the pattern. Wildcard Binds are
@@ -2171,8 +2175,8 @@ object desugar {
21712175 Apply (rhsSelect(gen, flatMapName), makeLambda(gen, cont))
21722176 case (gen : GenFrom ) :: rest
21732177 if sourceVersion.isAtLeast(`3.7`)
2174- && rest.dropWhile(_.isInstanceOf [GenAlias ]).headOption.forall(e => e.isInstanceOf [GenFrom ]) // possible aliases followed by a generator or end of for
2175- && ! rest.takeWhile(_.isInstanceOf [GenAlias ]).exists(a => isGivenPattern (a.asInstanceOf [GenAlias ].pat)) =>
2178+ && rest.dropWhile(_.isInstanceOf [GenAlias ]).headOption.forall(e => e.isInstanceOf [GenFrom ]) // possible aliases followed by a generator or end of for
2179+ && ! rest.takeWhile(_.isInstanceOf [GenAlias ]).exists(a => isNestedGivenPattern (a.asInstanceOf [GenAlias ].pat)) =>
21762180 val cont = makeFor(mapName, flatMapName, rest, body)
21772181 val selectName =
21782182 if rest.exists(_.isInstanceOf [GenFrom ]) then flatMapName
0 commit comments