@@ -2044,12 +2044,16 @@ object desugar {
2044
2044
makeCaseLambda(CaseDef (gen.pat, EmptyTree , body) :: Nil , matchCheckMode)
2045
2045
}
2046
2046
2047
- /** Does this pattern define any given bindings */
2048
- def isGivenPattern (pat : Tree ): Boolean = pat.existsSubTree {
2047
+ def hasGivenBind (pat : Tree ): Boolean = pat.existsSubTree {
2049
2048
case pat @ Bind (_, pat1) => pat.mods.is(Given )
2050
2049
case _ => false
2051
2050
}
2052
2051
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
+
2053
2057
/** If `pat` is not an Identifier, a Typed(Ident, _), or a Bind, wrap
2054
2058
* it in a Bind with a fresh name. Return the transformed pattern, and the identifier
2055
2059
* that refers to the bound variable for the pattern. Wildcard Binds are
@@ -2171,8 +2175,8 @@ object desugar {
2171
2175
Apply (rhsSelect(gen, flatMapName), makeLambda(gen, cont))
2172
2176
case (gen : GenFrom ) :: rest
2173
2177
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)) =>
2176
2180
val cont = makeFor(mapName, flatMapName, rest, body)
2177
2181
val selectName =
2178
2182
if rest.exists(_.isInstanceOf [GenFrom ]) then flatMapName
0 commit comments