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

SA1101: "Prefix calls with this" incorrectly handles properties as expression bodies #1501

Closed
lowkay opened this issue Sep 18, 2015 · 11 comments
Assignees
Milestone

Comments

@lowkay
Copy link

lowkay commented Sep 18, 2015

When using expression bodies for properties the diagnostic for SA1101 is incorrectly detected when the property name is the same as a type/enum, i.e.

    public enum Lifetime
    {
        Persistent,

        Transient,

        Scoped
    }

   public class Example
    {
        public Lifetime Lifetime => Lifetime.Persistent;
        //                          ^ Diagnostic SA1101 incorrectly detected here.
    }

It is not detected if this is a declared getter:

   public class Example
   {
      public Lifetime Lifetime
      {
           get
           {
               return Lifetime.Persistent;
           }
      }
   }
@sharwell
Copy link
Member

Weird 🐛 catch!

@pdelvo
Copy link
Member

pdelvo commented Sep 19, 2015

Im currently looking into this and I have trouble reproducing this. Is the code you posted exactly the one that was reporting SA1101? Which version were you using?

@lowkay
Copy link
Author

lowkay commented Sep 21, 2015

Howdy,

It's using the latest pre-release from nuget. Take a look at the example solution here:
https://github.com/lowkay/StyleCopAnalyzerBugs/tree/master/Bug1501

@pdelvo
Copy link
Member

pdelvo commented Sep 21, 2015

bug1501
I tried to repro this with your project but I dont see any problem. I tried both beta12 (left) and the current master (right). Maybe someone else can try to repro it?

@lowkay
Copy link
Author

lowkay commented Sep 21, 2015

hmm, strange - no squiggle, but the build fails with SA1101 violations:

image

@pdelvo
Copy link
Member

pdelvo commented Sep 21, 2015

Wow thats weird! It shows up for me in the msbuild output as well but not the error list.

@lowkay
Copy link
Author

lowkay commented Sep 21, 2015

We've experienced some errors not getting into the error list before, always thought it was a VS bug - as we have quite a large solution and VS isn't always good at updating the error list and as I understand it adding the diagnostic is all you need to do and VS should update the relevant UX...

@pdelvo
Copy link
Member

pdelvo commented Sep 21, 2015

I am able to repro this in the debugger and I think that the bug is not our fault. Roslyns GetSymbolInfo in this case returns for Lifetime the type symbol of the enum, when run in the IDE but when run in msbuild (or our tester project) it returns the symbol of the property. I dont know why this happens. Im going to file a bug at the roslyn repo.

@lowkay
Copy link
Author

lowkay commented Sep 21, 2015

Cool, odd that it would behave differently just because of the initiating process (MSBuild vs IDE). Will be interesting to see what the outcome is from it!

@pdelvo
Copy link
Member

pdelvo commented Sep 21, 2015

I filed the bug report. Maybe it was some last minute bug fixing in the version that shipped in VS. (or there was a bug report that introduced this bug that didnt made it into VS)

pdelvo added a commit to pdelvo/StyleCopAnalyzers that referenced this issue Sep 21, 2015
@pdelvo
Copy link
Member

pdelvo commented Sep 21, 2015

I created a PR that works around this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants