-
Notifications
You must be signed in to change notification settings - Fork 26
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
False positives #125
Comments
Thanks for reporting! |
I cloned rubberduck and had a look. var subclass = Subclasses.Subclass(hwnd); Why not do I'm not sure about teaching the analyzer about |
About: var component = _state.ProjectsProvider.Component(target.QualifiedName.QualifiedModuleName); It is tricky as there are interfaces involved. The analyzer falls back on heuristics and assumes that disposables from methods are created. We need to add annotations to handle this case. Annotations have been discussed before but we have not pulled the trigger on them. |
using (var module = component.CodeModule)
{
} Reason IDISP007 nags here is again heuristics, it assumes that a property does not return a created disposable that the ~caller owns. Needs annotations #126 A property returning a created reference type is not awesome design if you ask me. |
For me it is easiest with many small issues. Also for discussion we have a gitter, everyone welcome! |
// IDISP003
void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)
=> ppTI = GetSafeRefTypeInfo(hRef); This looks like a bug, I'll try to repro and fix. |
Looks like I'm dumbing analysis in the switch also. |
Thank you very much for the responses! In future I will split them as one issue per. Regarding the annotations - to be honest, we were kicking around the same idea of annotating our project repository class? interface? to help us track whether it is the caller's responsibility to dispose the provided
Those all are managed by While we already have written some Roslyn analyzers for our project, this kind of analysis would be far too complicated and as such, I'd much rather piggyback on your excellent analyzers which already has identified a good number of legitimate misuses. |
If we add support for annotations we will have the analyzer check usages so burden will not be huge. Adding annotations is not going to be very hard, it mostly stuck on deciding on names of attributes etc. I created an issue for discussing annotations, please join use and bikeshed :D |
Confirming -- I noticed a similar false positives for IDISP007 as the case with the IDISP001 reported above. I assume this is due to using same heuristics so fixing the issue would address both rules? If that's not the case, I will make a separate issue. |
Closing this, open new issues if I forgot things. |
Thank you very much for sharing the analyzer. I'm in process of trying this out with Rubberduck-VBA. This project involves quite a lot of manual management due to deep COM interop and a large part of architecture relies on
IDisposable
interface to explicitly control the lifetime of wrapped COM objects.I've found few false positives. I do not know if those are something we can fix or enhance but I thought I'd at least point them out.
With
IDISP001
rule we are flagged here:The
component
here is aIDisposable
object which we obtain via the_projectsProvider.Component
. The intention with theProjectsRepository
is that the class is responsible for the lifetime of its objects, so thus we shouldn't dispose anything we get out of theProjectsRepository
.We have a similar situation here:
As above,
Subclass
returns aIDisposable
object from a cached collection.With
IDSIP007
rule we also get flagged here:In this case,
CodeModule
is similarly aIDisposable
object. However, theCodeModule
property reads:Thus,
using
is actually appropriate in this case since we get a new object and thus are responsible for disposing it.With
IDISP003
, we have a false positive for this code:This flags the
ppTI
as needing to be disposed. What I don't get, though is that the variable has type ofITypeInfo
, which does not implementIDisposable
. If I try to apply the quickfix, I get the following code:Which does not look at all appropriate to me.
Another example is here for this section of code:
For each case, the
result
is flagged in spite of the fact that it's a local variable and thus cannot be been previously assigned.I have not gone though all other issues and will update as I proceed.
I know we can add suppress message but I want to avoid suppressing it everything. We got about 1500 warnings and we're going to have to assess them one by one because of some false positives.
The text was updated successfully, but these errors were encountered: