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

Revert "Revert "Require partial method signatures to match" (47576) (#47879)" #53352

Merged
merged 20 commits into from Jun 10, 2021

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented May 12, 2021

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

@Youssef1313 Youssef1313 marked this pull request as ready for review May 12, 2021 07:22
@Youssef1313 Youssef1313 requested a review from a team as a code owner May 12, 2021 07:22
@Youssef1313 Youssef1313 changed the base branch from main to features/compiler May 12, 2021 08:00
@AlekseyTs
Copy link
Contributor

@Youssef1313 Could you provide details about what was the problem with the original change that got reverted?

@AlekseyTs AlekseyTs added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label May 12, 2021
@Youssef1313
Copy link
Member Author

@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))

@cston
Copy link
Member

cston commented May 12, 2021

what was the problem with the original change that got reverted?

#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.

@RikkiGibson RikkiGibson self-assigned this May 18, 2021
@@ -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>(
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member

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

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for confirming.

@cston
Copy link
Member

cston commented Jun 1, 2021

public partial V M1<V>() => default;

It looks like this should be U M1<U>() => default;. Otherwise the test appears identical to M3 below.


Refers to: src/Compilers/CSharp/Test/Symbol/Symbols/ExtendedPartialMethodsTests.cs:2807 in 4adfba6. [](commit_id = 4adfba6, deletion_comment = False)

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);
Copy link
Member

Choose a reason for hiding this comment

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

TypeParameters

Should these checks be using Parameters instead?

Copy link
Member Author

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.

Copy link
Member

@cston cston Jun 6, 2021

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.

Copy link
Contributor

@RikkiGibson RikkiGibson left a 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.

Co-authored-by: Rikki Gibson <rigibson@microsoft.com>
Comment on lines 3673 to 3679
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);
Copy link
Member

@cston cston Jun 10, 2021

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.

Suggested change
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());

Copy link
Member

@cston cston left a 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>
Copy link
Contributor

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.

Copy link
Member Author

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.

@RikkiGibson RikkiGibson merged commit 52dcaf5 into dotnet:features/compiler Jun 10, 2021
@RikkiGibson
Copy link
Contributor

Thanks for the contribution @Youssef1313!

@Youssef1313 Youssef1313 deleted the warn-wave branch June 10, 2021 19:42
333fred added a commit that referenced this pull request Jun 14, 2021
…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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
4 participants