Injected binders should be resilient to `GetBinder` calls
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Any time a binder is created/injected on-the-fly during binding, there is a risk that it could get dropped when it is used to bind an expression that involves getting more specific binders with `GetBinder`.
Using `LocalInProgressBinder` as an example (issue fixed in https://github.com/dotnet/roslyn/pull/75371):
This binder was injected when binding a local initializer to compute its constant value (`new LocalInProgressBinder(...)` in `SourceLocalSymbol.MakeConstantTuple`).
The binder keeps track of the `const` local being bound and helps avoid circularity issues.
But binding some expressions like `checked(x)` or `x switch { ... }` would involve a call to `GetBinder` and the `LocalInProgressBinder` would be lost, opening the compiler up to circularity issues.
Two possible solutions we discussed so far:
1. avoid injecting the binder on-the-fly (use a binder factory instead)
2. ensure that `GetBinder` maintains the injected binder
FYI @AlekseyTs
Contributor guide
Assessment
This issue has not been assessed yet.