Skip to content

Partial methods implementation should match declaration parameter ref kinds#25893

Merged
OmarTawfik merged 2 commits intodotnet:dev15.7.xfrom
OmarTawfik:fix-25399-partial-methods-different-ref-kind
Apr 5, 2018
Merged

Partial methods implementation should match declaration parameter ref kinds#25893
OmarTawfik merged 2 commits intodotnet:dev15.7.xfrom
OmarTawfik:fix-25399-partial-methods-different-ref-kind

Conversation

@OmarTawfik
Copy link
Copy Markdown
Contributor

Customer scenario

Customers should not be able to implement partial methods having parameters with a different ref kind than the definition. The compiler should produce diagnostics and prevent that. Currently, the following invalid code passes without errors:

partial class C {
    partial void M(in int i);
    partial void M(ref int i) {}  
}

Since this is a breaking change, @dotnet/roslyn-compat-council will be notified and will get approval before merging.

Bugs this fixes

Fixes #25399

Workarounds, if any

None.

Risk

Low risk. This is producing an error in a corner case scenario where code shouldn't have been allowed in first place.

Performance impact

Negligible.

Is this a regression from a previous update?

It is a breaking change.

How was the bug found?

Reported on GitHub by a contributor.

cc @dotnet/roslyn-compiler for review.

@OmarTawfik OmarTawfik added this to the 15.7 milestone Apr 2, 2018
@OmarTawfik OmarTawfik self-assigned this Apr 2, 2018
@OmarTawfik OmarTawfik requested a review from a team April 2, 2018 21:24
}

[Fact]
public void PartialMethodsConsiderRefKindDifferences_InWithRef()
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 2, 2018

Choose a reason for hiding this comment

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

PartialMethodsConsiderRefKindDifferences_InWithRef [](start = 20, length = 50)

Should probably fold out into the test matrix. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Partial methods cannot have out parameters, and there exists already a test for that.
What is the scenario you're proposing?


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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline. Either confirming CS759 is reported, or lookup the symbol table and confirm they're not merged.


In reply to: 178992135 [](ancestors = 178992135,178658268)

}

[Fact]
public void PartialMethodsWithInParameter_WithBody()
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 2, 2018

Choose a reason for hiding this comment

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

PartialMethodsWithInParameter_WithBody [](start = 20, length = 38)

in and ByVal can overload each other. Consider adding a test that overloading like that (and other supported overloading over ref-ness, if any) works properly for partial methods. #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 1), modulo suggested tests

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

@OmarTawfik
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler can I get another review?

1 similar comment
@OmarTawfik
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler can I get another review?


- Visual Studio 2017 version 15.7: https://github.com/dotnet/roslyn/issues/19792 C# compiler will now reject [IsReadOnly] symbols that should have an [InAttribute] modreq, but don't.
- Visual Studio 2017 version 15.7: https://github.com/dotnet/roslyn/pull/25131 C# compiler will now check `stackalloc T [count]` expressions to see if T matches constraints of `Span<T>`.
- Visual Studio 2017 version 15.7: https://github.com/dotnet/roslyn/issues/25399 C# compiler will now produce errors if partial methods parameters have different ref-kinds in implementation vs definition.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume this was blessed by the Compat Council.
If not, please do (before merging).

Copy link
Copy Markdown
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 modulo compat council approval.

@OmarTawfik
Copy link
Copy Markdown
Contributor Author

@jcouv yes. They already approved.
@jaredpar can you please approve for sign off?

@jaredpar
Copy link
Copy Markdown
Member

jaredpar commented Apr 5, 2018

approved

@OmarTawfik OmarTawfik merged commit ec3410b into dotnet:dev15.7.x Apr 5, 2018
@OmarTawfik OmarTawfik deleted the fix-25399-partial-methods-different-ref-kind branch April 5, 2018 03:20
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.

4 participants