-
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
Revert "Revert "Require partial method signatures to match" (47576) (#47879)" #53352
Conversation
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
@Youssef1313 Could you provide details about what was the problem with the original change that got reverted? |
@AlekseyTs, After @cston initially implemented it, it got temporarily reverted to be added later into a warning wave. This PR gets @cston work again by reverting the revert. And on top of that, extend the warning per #47838 (this was confirmed in LDM - see #47841 (comment)) |
#47576 was reverted because it was late in the 16.8 release cycle to take a change that affects warnings. The expectation was we'd re-introduce the change in a later warning wave. |
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
@@ -1169,7 +1169,7 @@ private bool IsValidOverrideReturnType(Symbol overridingSymbol, TypeWithAnnotati | |||
location, | |||
new FormattedSymbol(overridingParameter, SymbolDisplayFormat.ShortFormat)); | |||
|
|||
internal static void CheckValidNullableMethodOverride<TArg>( | |||
internal static bool CheckValidNullableMethodOverride<TArg>( |
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 adding a doc comment for the return value.
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.
Doc'ed. Would like @cston to confirm the correctness of the doc comment.
if (!returnTypesEqual | ||
&& !SourceMemberContainerTypeSymbol.IsOrContainsErrorType(implementation.ReturnType) | ||
&& !SourceMemberContainerTypeSymbol.IsOrContainsErrorType(definition.ReturnType)) | ||
bool hasTypeDifferences = !constructedDefinition.ReturnTypeWithAnnotations.Equals(implementation.ReturnTypeWithAnnotations, TypeCompareKind.AllIgnoreOptions); |
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.
Does this introduce new errors when one of the partial declarations has an error type for its return type?
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.
Does this introduce new errors when one of the partial declarations has an error type for its return type?
Yes, I believe so, but if the return types are distinct, arguably we should report a warning, even if one or both of those return types is an error type.
@@ -741,6 +752,16 @@ private static void PartialMethodConstraintsChecks(SourceOrdinaryMethodSymbol de | |||
var typeParameter1 = typeParameters1[i]; | |||
var typeParameter2 = typeParameters2[i]; | |||
|
|||
// TODO: Should report on type parameter name differences? |
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.
Sure, why not? However, it feels reasonable to do this at the same time as we check the parameter name difference. i.e. if any type parameter names or parameter names or parameter nullabilities differ, for example, report a single diagnostic on the implementation.
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 I didn't do that because LDM notes didn't mention this at all. So I wasn't sure if it needs to be discussed in a later LDM first?
If it's okay to go ahead and do that directly in that PR, I'll.
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.
I feel that this language supports us reporting warnings on type parameter name differences:
We will add a new warning wave warning for all other syntactic differences between partial method implementations.
I will go ahead and ping language design internally to see if there is any objection, but I'm fairly confident that this will be accepted.
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 I did it in the last commit (modulo tests - will fix the failing tests after you confirm). In case there are any concerns not to do this, I'll revert.
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.
LDM has confirmed that type parameter name differences should also cause the warning.
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.
Thanks for confirming.
var type1 = ns.GetTypeMembers("MyClass").Single() as NamedTypeSymbol; | ||
Assert.Equal(0, type1.TypeParameters.Length); | ||
var f = type1.GetMembers("F").Single() as MethodSymbol; | ||
Assert.Equal(2, f.TypeParameters.Length); |
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.
@cston The number of parameters is 1, not 2. So this change will fail the test.
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.
The number of parameters is 1, not 2. So this change will fail the test.
I meant that any asserts should probably check Parameters
rather than TypeParameters
since, unlike the following test, the parameter names are distinct not the type parameter names.
Co-authored-by: Rikki Gibson <rigibson@microsoft.com>
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.
Sorry for delay on this. It looks very close now. Just had some minor suggestions on wording/formatting.
...Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Rikki Gibson <rigibson@microsoft.com>
Assert.Equal(0, type1.TypeParameters.Length); | ||
var f = type1.GetMembers("F").Single() as MethodSymbol; | ||
Assert.Equal(2, f.TypeParameters.Length); | ||
var param1 = f.TypeParameters[0]; | ||
var param2 = f.TypeParameters[1]; | ||
Assert.Equal("T", param1.Name); | ||
Assert.Equal("U", param2.Name); |
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 checking the parameter name rather than type parameter names since it is the parameter name that is distinct.
Assert.Equal(0, type1.TypeParameters.Length); | |
var f = type1.GetMembers("F").Single() as MethodSymbol; | |
Assert.Equal(2, f.TypeParameters.Length); | |
var param1 = f.TypeParameters[0]; | |
var param2 = f.TypeParameters[1]; | |
Assert.Equal("T", param1.Name); | |
Assert.Equal("U", param2.Name); | |
Assert.Equal("T t", f.Parameters[0].ToTestDisplayString()); |
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 @Youssef1313.
<value>Partial method declarations '{0}' and '{1}' have signature differences.</value> | ||
</data> | ||
<data name="WRN_PartialMethodTypeDifference_Title" xml:space="preserve"> | ||
<value>Partial method declarations have differences in parameter names, parameter types, or return types.</value> |
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.
Ah, hate to do this last minute, but this message should be changed to be in sync with the other message.
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 My bad! Fixing now.
Thanks for the contribution @Youssef1313! |
…ures/interpolated-string * upstream/main: (95 commits) Update official build number in separate job Update Language Feature Status.md (#54015) Remove IRazorDocumentOptionsService inheritance interface (#54047) Fix comment Simplify Do not create a cache field for lambda if it depends on caller's type argument (#44939) Documentation Documentation Documentation Update test impls Just pass null Pull diagnostics should just request from the doc, not the whole project. Add test plan for file-scoped namespace (#54003) Add source build to official build Improved nullable 'is' analysis (#53311) Multi session service (#53762) Resolve Versions.props conflicts Revert "Revert "Require partial method signatures to match" (47576) (#47879)" (#53352) Broaden enforcement on prototype marker (#53886) Update Language Feature Status.md (#53926) ...
This PR brings back #47576, and changes the warning level to 6, and also extend the warning for parameter name differences.
Fixes #47838
Fixes #52520