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

Misleading error message in case of ref-returning this in a reference type #15704

Closed
alrz opened this issue Dec 6, 2016 · 4 comments
Closed
Assignees
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@alrz
Copy link
Member

alrz commented Dec 6, 2016

Version Used: 0694d5c

Steps to Reproduce:

public class C 
{
    public ref C M()
    {
        return ref this;
    }
}

Expected Behavior:

error CS1605: Cannot use 'this' as a ref or out value because it is read-only

Actual Behavior:

error CS8170: Struct members cannot return 'this' or other instance members by reference

@jcouv
Copy link
Member

jcouv commented Dec 6, 2016

FYI @VSadov

@gafter
Copy link
Member

gafter commented Dec 15, 2016

Actually, I think the existing error is not bad. If we add support for readonly refs, this would still be an error for the reason mentioned in the diagnostic.

@alrz
Copy link
Member Author

alrz commented Dec 15, 2016

I don't get it. the error is clearly misleading as I'm not using a struct. What you say applies to the "expected" message, not actual.

@gafter
Copy link
Member

gafter commented Dec 15, 2016

Yes, I see you're right.

@jaredpar jaredpar added the Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. label Jan 9, 2017
@jaredpar jaredpar modified the milestones: 2.1, 2.0 (RC.3) Jan 9, 2017
@jaredpar jaredpar modified the milestones: 15.3, 15.1 Mar 9, 2017
@jaredpar jaredpar modified the milestones: 15.3, 15.later May 15, 2017
@sharwell sharwell added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label May 18, 2017
@sharwell sharwell modified the milestones: 15.3, 15.later May 18, 2017
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. Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

6 participants