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

Inaccurate error message when attempting to use a property as a ref #60807

Closed
svick opened this issue Apr 17, 2022 · 5 comments
Closed

Inaccurate error message when attempting to use a property as a ref #60807

svick opened this issue Apr 17, 2022 · 5 comments
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@svick
Copy link
Contributor

svick commented Apr 17, 2022

Version Used: current main on SharpLab (eb3ccc5)

Steps to Reproduce:

Compile the following code:

ref int y = ref C.P;

class C
{
    public static int P { get; set; }
}

Actual Behavior:

error CS0206: A property or indexer may not be passed as an out or ref parameter

Expected Behavior:

An error message that does not talk about ref parameters, since no method with a ref parameter is involved.

@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 17, 2022
@svick svick added the Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. label Apr 17, 2022
@jcouv jcouv added the Bug label Apr 21, 2022
@jcouv jcouv added this to the Backlog milestone Apr 21, 2022
@jcouv jcouv added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 21, 2022
@ArcadeMode
Copy link
Contributor

ArcadeMode commented Oct 16, 2022

I will attempt to clarify this by instead showing CS8145: Auto-implemented properties cannot return by reference when attempting to use ref with property access.

After taking a close look at the code and spec regarding ref/out I concluded my initial suggestion made little sense - especially given the more recent language feature which support ref properties (like this). So clarifying the message that this error does not encompass all properties and not just parameters seems more logical. My proposed change is now to update the error message to An indexer or auto-implemented property may not be used as an out or ref value.

@svick
Copy link
Contributor Author

svick commented Oct 17, 2022

@ArcadeMode
Copy link
Contributor

ArcadeMode commented Oct 17, 2022

@svick Thanks for the feedback. I think the ref-returning aspect should then be highlighted (without the auto-property part). e.g. a non ref-returning property or indexer may not be used as an out or ref value

@svick
Copy link
Contributor Author

svick commented Oct 17, 2022

@ArcadeMode Yeah, that sounds good to me.

ArcadeMode added a commit to ArcadeMode/roslyn that referenced this issue Oct 17, 2022
@cston
Copy link
Member

cston commented Oct 18, 2022

Fixed in #64764.

@cston cston closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

No branches or pull requests

4 participants