-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Prefer delegate-accepting overload in error messages when lambda argument is present #81275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ds with lambda arguments Co-authored-by: CyrusNajmabadi <[email protected]>
Co-authored-by: CyrusNajmabadi <[email protected]>
…errors over lambda conversion errors Co-authored-by: CyrusNajmabadi <[email protected]>
Done! The fix now also improves issue #10672. For the scenario
The fix detects when lambda conversion errors exist alongside bad arguments in non-lambda positions, and when a delegate-accepting overload is available, it reports the non-lambda argument errors instead. Added test case |
|
@copilot tests fail in "DelegateTypeTests" and "SemanticErrorTests". See if these failures are appropriate and the tests should be updated. Or if this has revealed a problem with this approach. |
…ests and SemanticErrorTests Co-authored-by: CyrusNajmabadi <[email protected]>
The test failures were appropriate - they reflect the improved error reporting behavior. Updated the test expectations in both test suites: DelegateTypeTests (4 tests):
SemanticErrorTests (1 test):
All 819 DelegateTypeTests and 784 SemanticErrorTests now pass. These changes align with the fix's intent: prefer delegate-accepting overloads when reporting errors for lambda arguments. Commit: 35b5f35c |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
Outdated
Show resolved
Hide resolved
…ion/OverloadResolutionResult.cs
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
Outdated
Show resolved
Hide resolved
…ion/OverloadResolutionResult.cs
Plan: Improve error message for overloaded generic delegate-accepting methods ✅
When overload resolution fails and there's a lambda/anonymous method argument, the compiler now prefers reporting errors about overloads that accept delegates in that position, and also prefers reporting errors about non-lambda arguments when both lambda and non-lambda errors exist.
Implementation Plan:
Changes Made:
OverloadResolutionResult.cs:HadBadArgumentsto detect when a lambda is converting to a non-delegate typeGetFirstMemberKindto prefer delegate-accepting candidates when lambda arguments are presentHadLambdaConversionErrorto check if there are bad arguments in non-lambda positionsHasDelegateParameterForLambdaArgumenthelper methodHasLambdaArgumentConvertingToNonDelegatehelper methodHasBadArgumentsInNonLambdaPositionshelper methodTest Updates:
DelegateTypeTests.OverloadResolution_33,OverloadResolution_35,OverloadResolution_36,OverloadResolution_38SemanticErrorTests.CS1061ERR_NoSuchMemberOrExtension05Issues Fixed:
Issue #21950:
Issue #10672:
Additional improvements (reflected in updated tests):
Select, now prefersEnumerable.Select(takesFunc) overQueryable.Select(takesExpression<Func>)All test failures were appropriate - they reflected the improved error reporting behavior.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.