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
- fix for issue dotnet#17711: IDE0009 wrongly generated when using the base keyword — committed to RobSiklos/roslyn by RobSiklos 7 years ago
- additional commit for issue #17711 - adding unit tests for fields. — committed to RobSiklos/roslyn by RobSiklos 7 years ago
@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:
The equivalent code in Visual Basic produces the same problem:
Additional information for getting this figured out:
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.
The source code for this feature is in AbstractQualifyMemberAccessDiagnosticAnalyzer.cs and its derived types
The tests for this feature are in QualifyMemberAccessTests.cs and QualifyMemberAccessTests.vb