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

Add IMethodSymbol.IsReadOnly to public API #34514

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Mar 27, 2019

This proposes adding the following public API to IMethodSymbol:

/// <summary>
/// Indicates whether the method is readonly, i.e.
/// whether 'this' is 'ref readonly' in the scope of the method.
/// </summary>
bool IsReadOnly { get; }

Note that once the last prototype comments are addressed, the check methodSymbol.IsReadOnly will be basically equivalent to methodSymbol.ThisParameter.RefKind == RefKind.In.

@RikkiGibson RikkiGibson requested review from a team as code owners March 27, 2019 17:25
@333fred
Copy link
Member

333fred commented Mar 27, 2019

@RikkiGibson tests are failing.

@333fred
Copy link
Member

333fred commented Mar 27, 2019

I don't see any tests for these APIs. Do we already have them?

@333fred
Copy link
Member

333fred commented Mar 27, 2019

Done review pass (commit 1)

@RikkiGibson
Copy link
Contributor Author

F:\workspace\_work\1\s\src\Compilers\CSharp\Portable\Symbols\Metadata\PE\PEMethodSymbol.cs(1043,32): error CS0507: 'PEMethodSymbol.IsDeclaredReadOnly': cannot change access modifiers when overriding 'public' inherited member 'MethodSymbol.IsDeclaredReadOnly' [F:\workspace\_work\1\s\src\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj]

Weird, it seems like this error should have come up right away locally. Will fix.

@RikkiGibson
Copy link
Contributor Author

I don't see any tests for these APIs. Do we already have them?

The implementations via MethodSymbol are tested already. Maybe I should add one that goes specifically through SemanticModel APIs?

@333fred
Copy link
Member

333fred commented Mar 27, 2019

The implementations via MethodSymbol are tested already. Maybe I should add one that goes specifically through SemanticModel APIs?

This would probably be good to test. We have a number of public and internal APIs already that are implemented differently, if we ever change the internal version it'd be good to verify the public ones as well.

@RikkiGibson RikkiGibson requested a review from jaredpar March 27, 2019 22:48
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.

LGTM (commit 5) with the namespace change revert and Chuck's suggestion of ExceptionUtilities.Unreachable

@gafter
Copy link
Member

gafter commented Mar 28, 2019

I don’t think we need two APIs here. The user should only (usually) care about effective. If they care about the syntax that was used they can look at the syntax. I recommend IsReadonly to tell if it is effectively readonly for any reason. (We don’t have DeclaredPrivate to distinguish a member that has the private modifier, versus only private because it was declred in a class versus an interface) #Resolved

@RikkiGibson
Copy link
Contributor Author

How does this affect SymbolDisplayVisitor? Should it just always display a readonly keyword for an effectively readonly method?

@RikkiGibson
Copy link
Contributor Author

This can be deferred until after the feature gets merged, especially because as the PR description notes, "effective readonly" can be checked via methodSymbol.ThisParameter.RefKind

@RikkiGibson RikkiGibson force-pushed the readonly-members-public-api branch from ef0467b to b765226 Compare April 1, 2019 23:48
@RikkiGibson RikkiGibson changed the title Add IsDeclaredReadOnly and IsEffectivelyReadOnly to public API Add IMethodSymbol.IsReadOnly to public API Apr 2, 2019
@RikkiGibson
Copy link
Contributor Author

The public API has been simplified down to IMethodSymbol.IsReadOnly. This won't have a negative impact on symbol display--we've decided that if there a few scenarios where 'readonly' is shown for an "effectively readonly" metadata symbol where the keyword wasn't explicitly provided in source, that's OK.

@RikkiGibson RikkiGibson requested a review from gafter April 2, 2019 00:44
Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

Please make this API work for reduced extension methods.

@RikkiGibson RikkiGibson requested review from gafter, 333fred and cston and removed request for gafter April 2, 2019 18:46
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.

LGTM (commit 12)

@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler Could I get a second sign-off please?

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@RikkiGibson RikkiGibson merged commit cfea028 into dotnet:features/readonly-members Apr 3, 2019
@RikkiGibson RikkiGibson deleted the readonly-members-public-api branch April 3, 2019 02:04
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