roslyn: IDE0009 wrongly generated when using the base keyword

Version Used: VS2017 15.0.0-RTW+26228.4

Steps to Reproduce: Consider this code

class A
{
    public virtual int Value => 5;
}

class B : A
{
    public override int Value => base.Value + 6; // warning here
}

Expected Behavior: No warning generated for IDE0009 on the marked line

Actual Behavior: IDE0009 is generated here

The analysis is completely wrong. Applying ‘this’ would create an infinite loop. The property does not need to be an expression body for IDE0009 to be generated. Value { get { base.Value + 6; } } will cause the warning as well.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 26 (26 by maintainers)

Commits related to this issue

Most upvoted comments

@RobSiklos I was able to reproduce a similar error by using Visual Studio 2017 version 15.2. Starting with pull request #19576 (merged yesterday), you’ll need Visual Studio 2017 15.3 Preview 1 or newer to develop Roslyn. While it still compiles using an older version, it seems the error message you get when you open a VB file is pretty terrible.

If you don’t want to update, you can create a branch for your work off of commit 7eba8523896899e9db5b5faa4c2de3abba44e288. At this point there are not likely to be merge conflicts when you submit your PR.

@sharwell Sure - if someone else wants it, they can take it.

I’m reserving this for a new first time contributor for the next three days.

Interested in trying your hand at this? Here’s what you need to know:

  1. If you are serious about working on this, add a comment here. While multiple people are allowed to participate, I’m willing to go out of my way to make sure the first contributor working on this gets their code merged into Roslyn.
  2. I know more about this issue than I’ve provided here. If you get stuck, ask any questions you want and I’ll fill out details. I don’t want this to be a boring task, but I also don’t want you to get stuck.

The equivalent code in Visual Basic produces the same problem:

Public Class A
    Public Overridable ReadOnly Property Value As Integer
End Class

Public Class B
    Inherits A

    Public Overrides ReadOnly Property Value As Integer
        Get
            Return MyBase.Value + 1
        End Get
    End Property
End Class

Additional information for getting this figured out:

  1. There is a missing step in the Steps to Reproduce. You need to make sure you have the IDE configured to prefer to qualify property accesses.

    image

    image

  2. The source code for this feature is in AbstractQualifyMemberAccessDiagnosticAnalyzer.cs and its derived types

  3. The tests for this feature are in QualifyMemberAccessTests.cs and QualifyMemberAccessTests.vb