DevDiv #1024137 - Part 1: "this" in C# iterators and async
When the callstack tells us that we're in a state machine MoveNext method, we want to bind as though we're really in the iterator or async method that caused the state machine to be generated. Parameters and locals are handled by special binders, but "this" and "base" won't work unless the binder has an appropriate ContainingType, which in turn depends on ContainingMemberOrLambda.
Unfortunately, the generated code (and the custom debug info) lacks sufficient information to map back to a single member. All we get is the name of the member in the mangled name of the state machine type. We apply a heuristic to choose an appropriate overload, if there are multiple, and accept that sometimes we will pick the wrong one. We believe that picking the wrong one will be benign since the binder uses relatively few properties of the ContainingMemberOrLambda and the ones it does (mainly, ContainingType) are consistent across all overloads.
Bonus: merge ThisReferenceRewriter into CapturedVariableRewriter. This saves us a pass over the bound tree and eliminates an intermediate state in which "this" has the wrong type (ThisReferenceRewriter used to break it and let CapturedVariableRewriter correct it).
TODO: Part 2 - "Me" in VB iterators and async.
TODO: Part 3 - "this" in anonymous functions.
CR: ChuckS, KevinH (changeset 1357667)
↧