-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Continue visiting bad named argument if not target-typed in NullableWalker #73326
Conversation
// We flush the completion with a plausible/dummy type and remove it. | ||
completion(TypeWithAnnotations.Create(argument.Type)); | ||
TargetTypedAnalysisCompletion.Remove(argumentNoConversion); | ||
|
||
Debug.Assert(parameter is not null || method is ErrorMethodSymbol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RikkiGibson @dotnet/roslyn-compiler for a second review, thanks |
public async Task M2() => await Task.Yield(); | ||
} | ||
"""; | ||
CreateCompilation(source).VerifyDiagnostics( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider adjusting the scenario so that a nullable diagnostic is expected or something like that, to show that nullable analysis is definitely occurring here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean inside the lambda, no diagnostics will be reported there since it's a bad call and hence diagnostics are disabled inside:
roslyn/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Lines 6743 to 6747 in c23414e
// We disable diagnostics when: | |
// 1. the containing call has errors (to reduce cascading diagnostics) | |
// 2. on implicit default arguments (since that's really only an issue with the declaration) | |
var previousDisableDiagnostics = _disableDiagnostics; | |
_disableDiagnostics |= node.HasErrors || defaultArguments[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm! (no action needed in that case.)
} | ||
continue; | ||
} | ||
|
||
// In error recovery with named arguments, target-typing cannot work as we can get a different parameter type | ||
// from our GetCorrespondingParameter logic than Binder.BuildArgumentsForErrorRecovery does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments make it seem like we are working around an inconsistency between GetCorrespondingParameter
and BuildArgumentsForErrorRecovery
. Should we make some change to ensure that these methods behave consistently? Would that remove the need for some of the complexity in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I think we could try to do that. Probably as a follow up (if it didn't work out, this would still be a valid fix)?
EDIT: Looking into this more, it doesn't seem very easy to make GetCorrespondingParameter consistent with BuildArgumentsForErrorRecovery - the latter does lots of heuristics and works against all overloads unlike the former. In general, I'm not sure it would be worth the work given this is just about error scenarios.
This is a follow up on #72635 - slight refactoring to only perform the short-circuit if we have a target-typed handler registered, not always. Avoids skipping visiting bad nodes in scenarios that can work. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2045970.