Skip to content

Adjust tuple and nullability checks on duplicate implementations and type constraints#38563

Merged
jcouv merged 10 commits intodotnet:masterfrom
jcouv:nullable-constraints
Sep 25, 2019
Merged

Adjust tuple and nullability checks on duplicate implementations and type constraints#38563
jcouv merged 10 commits intodotnet:masterfrom
jcouv:nullable-constraints

Conversation

@jcouv
Copy link
Copy Markdown
Member

@jcouv jcouv commented Sep 6, 2019

Fixes #38560 (open questions on duplicate implementations with nullability differences): in this change, we're treating such duplicates (whether direct or indirect) as an error (instead of a warning previously), except that we're relaxing the comparison to account for oblivious.
Note: there is still an active email thread on this behavior, as other nullability checks only produce warnings (not errors).

Fixes #38427 (missing diagnostic on duplicate type constraint with tuple name differences): in this change, we're treating such duplicates as an error, as well as duplicate type constraints with any nullability differences.

At the same time, I'm fixing a small issue with how those duplicates are checked: we were not detecting duplicates when they differed in tuple names and nullability at the same time.

@jcouv jcouv added this to the 16.4.P1 milestone Sep 6, 2019
@jcouv jcouv self-assigned this Sep 6, 2019
@jcouv jcouv marked this pull request as ready for review September 9, 2019 17:31
@jcouv jcouv requested a review from a team as a code owner September 9, 2019 17:31
@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Sep 13, 2019
@jcouv jcouv force-pushed the nullable-constraints branch from 1cfd986 to 71f99fc Compare September 13, 2019 21:47
@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Sep 13, 2019
@jcouv jcouv force-pushed the nullable-constraints branch from 71f99fc to de567fb Compare September 13, 2019 22:09
@jcouv jcouv modified the milestones: 16.4.P1, 16.4 Sep 13, 2019
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 16, 2019

Choose a reason for hiding this comment

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

WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList [](start = 62, length = 55)

From the description of this PR I got an impression that we should report an error now: "we're treating such duplicates (whether direct or indirect) as an error (instead of a warning previously)" #Closed

Copy link
Copy Markdown
Member Author

@jcouv jcouv Sep 16, 2019

Choose a reason for hiding this comment

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

Sorry, the compat council went back and forth on this and I forgot to update the description. We're sticking with a warning as opposed to an error because of multi-assembly scenarios. #Resolved

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 16, 2019

Choose a reason for hiding this comment

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

if (!other.Equals(@interface, TypeCompareKind.ObliviousNullableModifierMatchesAny)) [](start = 32, length = 83)

Should we still report a warning for an oblivious mismatch? #Closed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think so. That seems the most likely/common/useful scenario: you have a base type with oblivious from a library, then your type implemented the interface with specific nullability.


In reply to: 324916964 [](ancestors = 324916964)

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 16, 2019

Choose a reason for hiding this comment

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

expected [](start = 16, length = 8)

Remove? #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 16, 2019

Choose a reason for hiding this comment

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

expected [](start = 16, length = 8)

remove? #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 17, 2019

Choose a reason for hiding this comment

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

I, I<object?> [](start = 29, length = 21)

Should we report a warning even for an oblivious mismatch when it happens for interfaces directly present in the base list? #Closed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm going for an approach mimicking tuple name differences. We could have special rules for nullability, but I'm not sure it helps or is worthwhile.
The email thread landed on warnings for all cases, which is also consistent with the general approach we took for nullability.
Do you think it should be an error?


In reply to: 325296374 [](ancestors = 325296374)

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 17, 2019

Choose a reason for hiding this comment

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

~TypeCompareKind.ObliviousNullableModifierMatchesAny [](start = 96, length = 52)

Does this make any difference? Since we are ignoring any nullable differences. #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Sep 17, 2019

Done with review pass (iteration 8) #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Sep 18, 2019

Choose a reason for hiding this comment

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

continue; [](start = 32, length = 9)

Do we want to continue here though? This will drop the interface from the list. How do we decide which one is better to keep? Perhaps we should report a warning and keep it? Or report a different warning that would make it clear that the thing is ignored? #Closed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This continue is scoped to foreach. It doesn't affect the list of interfaces that are collected.
Added test to illustrate and removed both continue statements to improve readability.


In reply to: 325899242 [](ancestors = 325899242)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, my mistake


In reply to: 326305398 [](ancestors = 326305398,325899242)

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Sep 18, 2019

Done with review pass (iteration 9). #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 10), assuming tests are passing.

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Sep 19, 2019

@dotnet/roslyn-compiler for a second review. Thanks

@jcouv jcouv force-pushed the nullable-constraints branch from 55d5424 to fec2789 Compare September 20, 2019 17:45
@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Sep 20, 2019

Rebased to resolve conflict on doc file.
@dotnet/roslyn-compiler for a second review. Thanks

@jcouv jcouv force-pushed the nullable-constraints branch 2 times, most recently from 37492a9 to b70a55f Compare September 20, 2019 17:47
@jcouv jcouv force-pushed the nullable-constraints branch from b70a55f to 705ab18 Compare September 20, 2019 17:48
@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Sep 23, 2019

@dotnet/roslyn-compiler for a second review. Thanks

1 similar comment
@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Sep 24, 2019

@dotnet/roslyn-compiler for a second review. Thanks

@333fred
Copy link
Copy Markdown
Member

333fred commented Sep 25, 2019

Consider adding a test that is explicitly about the mismatched tuple names and does not involve nullability in any way.

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 10) with possible test suggestion.

@jcouv
Copy link
Copy Markdown
Member Author

jcouv commented Sep 25, 2019

@333fred The tuple scenario with no nullability differences is covered in tuple tests (CodeGenTupleTests, see DuplicateInterfaceDetectionWithDifferentTupleNames_02 for example).

@jcouv jcouv merged commit 3ad760b into dotnet:master Sep 25, 2019
@jcouv jcouv deleted the nullable-constraints branch September 25, 2019 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refine nullability checks on interface implementations Check for matching tuple names missing in type constraints

3 participants