Use static foreach for correct scope inference
#8123
Merged
static foreach for correct scope inference
#8123