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

Partial properties: diagnostics for mismatch between parts #73250

Conversation

RikkiGibson
Copy link
Contributor

Test plan: #73090

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 26, 2024
@RikkiGibson RikkiGibson changed the base branch from main to features/partial-properties April 26, 2024 23:35
@RikkiGibson RikkiGibson added New Feature - Partial Properties and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 26, 2024
@RikkiGibson RikkiGibson changed the title Diagnostics for mismatch between partial property parts Partial properties: diagnostics for mismatch between parts Apr 30, 2024
@@ -145,7 +145,18 @@ internal sealed override ImmutableArray<string> NotNullWhenFalseMembers
bool isNullableAnalysisEnabled,
BindingDiagnosticBag diagnostics) :
base(containingType, syntax.GetReference(), location, isIterator: false,
MakeModifiersAndFlags(property, propertyModifiers, isNullableAnalysisEnabled))
MakeModifiersAndFlags(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal of this change is to make it so the getter symbol in public virtual T Prop => ... is not treated as introducing any of its own modifiers.

This makes the behavior of APIs like LocalAccessibility more consistent with properties declared using the accessor list syntax public virtual T Prop { get => ... }.

itemInspector = static obj => obj switch
{
null => "<null>",
string s => $@"""{s}""",
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 makes it easier to paste baselines in from an AssertEx.Equal failure, since the string values will already be quoted.

I didn't bother to do escaping here, if anything I would like to output a """-string only if the string is detected to contain any characters that need escaping. It's something which can be addressed when we hit it.

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 introduces a problem where every line of a VerifyIL baseline is quoted. I'll have to look at either adjusting that or reverting this change.

@RikkiGibson RikkiGibson marked this pull request as ready for review May 1, 2024 22:20
@RikkiGibson RikkiGibson requested a review from a team as a code owner May 1, 2024 22:20
@RikkiGibson
Copy link
Contributor Author

@jcouv @333fred This PR is ready for review. Please take a look at your convenience.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 9)

@jcouv jcouv self-assigned this May 2, 2024
Copy link
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.

Done review pass


[Fact]
public void TypeDifference_02()
{
Copy link
Member

Choose a reason for hiding this comment

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

Consider a test like this:

private partial int P1 { get; set; }
partial int P1 { private get => 1; private set {} }

public partial string? M2() => "";
}
""";

Copy link
Member

Choose a reason for hiding this comment

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

Please test in vs ref readonly with indexer parameters.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 16)

[Fact]
public void ModifierDifference_Accessibility_ExplicitDefault_01()
{
// only one part explicitly specifies the default accessibility
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 a similar test (default accessibility vs. explicit accessibility) for accessors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think test ModifierDifference_Accessibility_ExplicitDefault_02 is exercising the scenario adequately because it shows that:

  1. explicitly specifying the default accessibility on an accessor is an error
  2. a difference in accessor accessibility modifiers between parts is an error

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 19). Only one test suggestion left

Copy link
Member

@jcouv jcouv 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 (iteration 19)

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.

3 participants