Skip to content
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

Merged
merged 3 commits into from
May 10, 2024

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented May 3, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 3, 2024
@jjonescz jjonescz changed the title 2045970 nullable assert Continue visiting bad named argument if not target-typed May 3, 2024
@jjonescz jjonescz changed the title Continue visiting bad named argument if not target-typed Continue visiting bad named argument if not target-typed in NullableWalker May 3, 2024
@jjonescz jjonescz marked this pull request as ready for review May 3, 2024 15:34
@jjonescz jjonescz requested a review from a team as a code owner May 3, 2024 15:34
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter is not null

parameter is null in this code path.

@jjonescz
Copy link
Member Author

jjonescz commented May 6, 2024

@RikkiGibson @dotnet/roslyn-compiler for a second review, thanks

@RikkiGibson RikkiGibson self-assigned this May 8, 2024
public async Task M2() => await Task.Yield();
}
""";
CreateCompilation(source).VerifyDiagnostics(
Copy link
Contributor

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.

Copy link
Member Author

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:

// 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];

Copy link
Contributor

@RikkiGibson RikkiGibson May 9, 2024

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.
Copy link
Contributor

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?

Copy link
Member Author

@jjonescz jjonescz May 9, 2024

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.

@jjonescz jjonescz requested a review from RikkiGibson May 9, 2024 12:45
@jjonescz jjonescz merged commit 18614bc into dotnet:main May 10, 2024
24 checks passed
@jjonescz jjonescz deleted the 2045970-NullableAssert branch May 10, 2024 08:44
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 10, 2024
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Language Feature - Nullable Reference Types Nullable Reference Types untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants