-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Support nullable variance in interface and partial method implementation. #36663
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
Conversation
|
@agocke, @dotnet/roslyn-compiler Please review. #Closed |
| { | ||
| implementedMember = interfaceMember; | ||
| } | ||
| Action<DiagnosticBag, MethodSymbol, MethodSymbol, (TypeSymbol implementingType, bool isExplicit)> reportMismatchInReturnType = |
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.
Consider making these local functions so we can make them static and easily verify that they are not capturing. #ByDesign
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.
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.
Delegates for lambdas are cached automatically.
In reply to: 296389943 [](ancestors = 296389943,296380417)
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.
FWIW, for me it's less about caching and more about readability.
In reply to: 296390411 [](ancestors = 296390411,296389943,296380417)
| checkParameters: overridingProperty.SetMethod is null); | ||
| checkParameters: overridingProperty.SetMethod is null || | ||
| overriddenGetMethod?.AssociatedSymbol != overriddenProperty || | ||
| overriddenProperty.GetOwnOrInheritedSetMethod()?.AssociatedSymbol != overriddenProperty); |
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.
Could consider extracting this check to a helper, as we use it in multiple places. #WontFix
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.
Could consider extracting this check to a helper, as we use it in multiple places.
I do not believe it is worth doing just for portion of the condition, the entire condition is different.
In reply to: 296387584 [](ancestors = 296387584)
| } | ||
| CheckValidNullableMethodOverride(overridingMethod.DeclaringCompilation, overriddenMethod, overridingMethod, diagnostics, | ||
| checkReturnType ? | ||
| (diagnostics, overriddenMethod, overridingMethod, location) => diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInReturnTypeOnOverride, location) : |
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.
overriddenMethod, overridingMethod [](start = 66, length = 34)
Consider using _ for ignored parameter. #WontFix
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.
Consider using _ for ignored parameter.
I see no point in doing this, it is not hard for me to type the names and it is better for readability in my opinion. Also, I do not think both parameters can be named _.
In reply to: 296388073 [](ancestors = 296388073)
| (diagnostics, overriddenMethod, overridingMethod, location) => diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInReturnTypeOnOverride, location) : | ||
| (Action<DiagnosticBag, MethodSymbol, MethodSymbol, Location>)null, | ||
| checkParameters ? | ||
| (diagnostics, overriddenMethod, overridingMethod, overridingParameter, location) => |
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.
(diagnostics, overriddenMethod, overridingMethod, overridingParameter, location) => [](start = 53, length = 83)
nit: consider using a local function for those funcs in various invocations of CheckValidNullableEventOverride #ByDesign
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 using a local function for those funcs in various invocations of CheckValidNullableEventOverride
Lambdas are used intentionally to take advantage of automatic caching.
In reply to: 296389099 [](ancestors = 296389099)
| return; | ||
| } | ||
|
|
||
| if (reportMismatchInParameterType == null) |
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.
Consider moving this if before the previous one, and removing the reportMismatchInParameterType != null check from that one. #Closed
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.
| } | ||
| } | ||
|
|
||
| private static bool CheckValidNullableOverride( |
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.
CheckValidNullableOverride [](start = 28, length = 26)
nit: name of the method is a bit misleading as it doesn't actually perform a check. Maybe ShouldCheck...? #Resolved
| Symbol overriddenMember, | ||
| Symbol overridingMember) | ||
| { | ||
| if (overriddenMember is null || |
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: you could just return ! this condition. #Resolved
|
Done review pass (commit 2). Mostly looks good, just a couple of small formatting suggestions. #Resolved |
If not covered elsewhere, consider extending this test to add Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:11173 in aff03fd. [](commit_id = aff03fd, deletion_comment = False) |
I find existing coverage sufficient. In reply to: 504570605 [](ancestors = 504570605) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:11173 in aff03fd. [](commit_id = aff03fd, deletion_comment = False) |
jcouv
left a comment
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.
LGTM Thanks (iteration 2)
333fred
left a comment
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.
LGTM (commit 3)
Closes #35227.