Skip to content

Commit

Permalink
Merge pull request code-cracker#818 from giggio/gb/fix795
Browse files Browse the repository at this point in the history
Enable fields to be disposed when using member access expression
  • Loading branch information
carloscds authored Aug 15, 2016
2 parents cc53fd4 + db0df32 commit 965ba02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ private static bool CallsDisposeOnField(IFieldSymbol fieldSymbol, MethodDeclarat
var memberAccess = (MemberAccessExpressionSyntax)invocation.Expression;
if (memberAccess?.Name == null) return false;
if (memberAccess.Name.Identifier.ToString() != "Dispose" || memberAccess.Name.Arity != 0) return false;
if (!memberAccess.Expression.IsKind(SyntaxKind.IdentifierName)) return false;
return fieldSymbol.Equals(semanticModel.GetSymbolInfo(memberAccess.Expression).Symbol);
});
return hasDisposeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ public void Dispose() { }
await VerifyCSharpHasNoDiagnosticsAsync(source);
}

[Fact]
public async Task WhenAFieldThatImplementsIDisposableIsDisposedWithThisDoesNotCreateDiagnostic()
{
const string source = @"
using System;
namespace ConsoleApplication1
{
class TypeName : IDisposable
{
private D field = D.Create();
public void Dispose()
{
this.field.Dispose();
}
}
class D : IDisposable
{
public static D Create() => new D();
public void Dispose() { }
}
}";
await VerifyCSharpHasNoDiagnosticsAsync(source);
}

[Fact]
public async Task WhenAFieldThatImplementsIDisposableIsDisposedThroughImplicitImplementationDoesNotCreateDiagnostic()
{
Expand Down

0 comments on commit 965ba02

Please sign in to comment.