[release/8.0-staging] Prefer most derived member in Configuration Binder source generator #101686
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #101316 to release/8.0-staging
/cc @ericstj
Customer Impact
When binding a type that uses
new
to hide a member and changes the type of that member, Configuration Binder will fail to bind. This is inconsistent with the reflection binder, which binds all members.Regression
Not a regression, but a blocker when using the source-generator.
Testing
New automated tests added, sharing bits with partner team to validate scenario is unblocked.
Risk
Low. Previously the source generator would traverse the type hierarchy down to System.Object and use the lowest/base member definition. Now we’ll choose the highest/most derived.
It could mean that there were cases that produced compiler failures before that now become warnings. For example - a type hides a member to make it read-only. Previously the source generator would try to set that member and result in an error. Now the member will be ignored, just like any other read-only member. This new behavior is more desirable and consistent with the behavior of the source generator.
There's still a gap between the source-generator and the reflection binder. The reflection binder would set all members in the type hierarchy with the same configuration data - even if the member was hidden. We're not trying to replicate this behavior and have not heard customer feedback asking for that behavior in the source generator.