resolveForEachBinding static method
resolveBinding for a for-each loop variable: the resolved check, or null when the loop needs none.
A path with a real loop to hoist out of calls this ONCE before iterating and then ResolvedBinding.bind per element. The async state machine and the sync generator re-enter per item and have no such place to stand, so they call checkForEachBinding and pay the resolution each time.
A SSimpleIdentifier loop variable (for (x in xs)) carries no
annotation here — its type was written at its own declaration, which this
node does not reach — so it binds unchecked.
Implementation
static ResolvedBinding? resolveForEachBinding(
Environment env,
SAstNode? loopVariable,
) {
if (loopVariable is! SDeclaredIdentifier) return null;
return resolveBinding(env, loopVariable.type);
}