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

Always check get method parameters in override indexer #74337

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

RikkiGibson
Copy link
Contributor

Closes #73384

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 10, 2024
@RikkiGibson RikkiGibson marked this pull request as ready for review July 11, 2024 02:15
@RikkiGibson RikkiGibson requested a review from a team as a code owner July 11, 2024 02:15
@@ -16929,6 +16929,35 @@ class B2 : A<string>
Diagnostic(ErrorCode.ERR_ScopedMismatchInParameterOfOverrideOrImplementation, "F6").WithArguments("s").WithLocation(17, 32));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73384")]
public void Indexer_EscapeInGetter()
Copy link
Member

Choose a reason for hiding this comment

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

Do we have similar tests for interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No and we had a dupe of almost the same check which causes the error to get dropped. Fixing.

// (28,19): warning CS9191: The 'ref' modifier for argument 1 corresponding to 'in' parameter is equivalent to 'in'. Consider using 'in' instead.
// _ = c[ref x];
Diagnostic(ErrorCode.WRN_BadArgRef, "x").WithArguments("1").WithLocation(28, 19));
// (17,9): warning CS9196: Reference kind modifier of parameter 'ref readonly int x' doesn't match the corresponding parameter 'in int x' in overridden or implemented member.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have the inverse of this scenario in a test: override ref readonly with in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Implementation_RefReadonly_In_Indexer for example tests this scenario in an interface and implementation.

@@ -1028,9 +1028,7 @@ void checkSingleOverriddenMember(Symbol overridingMember, Symbol overriddenMembe
overridingMemberLocation,
overriddenMethod,
overridingMethod,
Copy link
Member

Choose a reason for hiding this comment

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

Was the checkReturnType value superfluous before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was only used to suppress nullable variance diagnostics related to the return type. The only time false was passed for it was for a property setter, which is going to return void anyway, so we don't really expect any nullable diagnostics related to the return type to occur.

Copy link
Member

Choose a reason for hiding this comment

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

So, I hate to be the voice of insanity, but IL doesn't require that set be a void-returning method. What do we do if we're overriding a non-void setter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change may cause redundant or strange nullable diagnostics to appear in that case. I am OK with that.

@jaredpar jaredpar added this to the 17.12 milestone Jul 11, 2024
@RikkiGibson RikkiGibson requested a review from jaredpar July 11, 2024 23:15
@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler for a second review

@RikkiGibson RikkiGibson merged commit a6824ae into dotnet:main Jul 12, 2024
24 checks passed
@RikkiGibson RikkiGibson deleted the scoped-error-override-indexer branch July 12, 2024 05:25
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 17.12, Next Jul 12, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

Errors for scoped differences in override indexers are missing in some cases
3 participants