File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
accepted/future-releases/0546-patterns Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -2303,6 +2303,17 @@ appears:
2303
2303
assign to the variable introduced by an initializing formal inside the
2304
2304
initializer list.*
2305
2305
2306
+ *It's still possible for a user to observe that a guard sees a different
2307
+ variable than the body if the guard closes over its variable and the body
2308
+ assigns to the body's variable. Preventing that by disallowing capturing a
2309
+ pattern variable in a guard would get in the way of common use cases like
2310
+ calling `Iterable.where()` or `Iterable.any()` in a guard. Preventing it by
2311
+ disallowing assignment in the body would be confusing for a variable that
2312
+ isn't declared `final` and might usefully be assigned. Instead, we minimize
2313
+ the chances of a user seeing that the guard has its own variable by
2314
+ disallowing assignment and accept that in rare cases, a user may still
2315
+ observe that the guard sees a different variable.*
2316
+
2306
2317
If the body of a switch statement or expression is reached through only a
2307
2318
single case, then it is executed in a new scope whose enclosing scope is the
2308
2319
case scope of that case. Otherwise, the body is executed in a new scope
You can’t perform that action at this time.
0 commit comments