louthy / language-ext

C# functional language extensions - a base class library for functional programming
MIT License
6.44k stars 417 forks source link

Add resharper attributes to tell the code analysis engine that the functions do not store delegates #123

Closed johannesegger closed 8 years ago

johannesegger commented 8 years ago

I get this error when using IfNone

image

This is not a problem as IfNone does not store the delegate. The fix is to add the following attribute to the method.

https://www.jetbrains.com/help/resharper/2016.1/Reference__Code_Annotation_Attributes.html#InstantHandleAttribute

louthy commented 8 years ago

@eggapauli I'm not adding Re-shaper dependencies to lang-ext, it's a massive code smell to include dependencies for tools that have nothing to do with the resulting code. So, I'm afraid to say that unfortunately the 'fix' is for you to find a way to tell Re-sharper to be less aggressive with its complaints.

johannesegger commented 8 years ago

The R# documentation says you can create external annotations and distribute them through NuGet packages, so you could completely separate the library from the R# annotations if you wanted to.

louthy commented 8 years ago

I should't need to create annotations, because there are no issues with the lang-ext, this is an issue with Resharper. There are no bugs here for me to deal with - it's a library, not a tooling platform.

Resharper is giving you spurious error messages, that is a problem in the Resharper product. If Resharper has no way for you to disable these false positives, or for you to create your own annotations, then I would suggest getting in touch with Jetbrains to find a solution - because it's their code that's at fault.

If I start adding bespoke attributes for every tool that has trouble with valid C# code then it will end up in a mess. I don't personally use Resharper, so I wouldn't even be able to test it; and even if you were to build an annotations package for me, I'd still have to maintain it long term.

Resharper isn't a 'default tool' (even if lots of people think it is), its popularity doesn't grant it any special status. Plenty of consumers of this library may wonder what all the 'attribute litter' is lying around throughout the library.

However, if there was an equivalent attribute in the System.Diagnostics.Contracts library, then I'd consider using it because it's already being used for the Pure annotations and it's part of the BCL. Otherwise, I'm sorry, but it's a no.

johannesegger commented 8 years ago

OK, you're right. It's R# that is wrong. Thanks for the detailed explanation. I understand your point of view.

IDisposable commented 8 years ago

100% this.