Skip to content

Commit b116a65

Browse files
committed
Fix analyzer and expand tests
1 parent 1911f6c commit b116a65

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

RubberduckCodeAnalysis/ChainedWrapperAnalyzer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ private static void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
3939
}
4040

4141
var expInterfaces = context.SemanticModel.GetTypeInfo(node.Expression).Type?.AllInterfaces;
42-
var nameInterfaces = context.SemanticModel.GetTypeInfo(node.Name).Type?.AllInterfaces;
42+
43+
var nameValue = node.Name.Parent.Parent is InvocationExpressionSyntax ? node.Name.Parent.Parent : node.Name;
44+
var nameInterfaces = context.SemanticModel.GetTypeInfo(nameValue).Type?.AllInterfaces;
4345

4446
if (!expInterfaces.HasValue || !nameInterfaces.HasValue)
4547
{

RubberduckTestsCodeAnalysis/RubberduckCodeAnalysisUnitTests.cs

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ public class ChainedWrapperUnitTests : ChainedWrapperAnalyzer
724724
{
725725
[Test]
726726
[Category("ChainedWrappers")]
727-
[Ignore("See #4377")]
728727
public void InterfaceContainsInterfaceType()
729728
{
730729
var test = @"namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
@@ -752,6 +751,76 @@ public void B()
752751
v.Execute().Execute();
753752
}
754753
}
754+
}";
755+
var diagnostics = GetSortedDiagnostics(new[] { test }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer());
756+
Assert.AreEqual("ChainedWrapper", diagnostics.Single().Descriptor.Id);
757+
}
758+
[Test]
759+
[Category("ChainedWrappers")]
760+
public void InterfaceContainsInterfaceType_Property()
761+
{
762+
var test = @"namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
763+
{
764+
public interface ISafeComWrapper
765+
{
766+
FooImp Value { get; }
767+
}
768+
769+
public abstract class Foo : ISafeComWrapper
770+
{
771+
public virtual FooImp Value => new FooImp();
772+
}
773+
774+
public class FooImp : Foo
775+
{
776+
public override FooImp Value => base.Value;
777+
}
778+
779+
public class D
780+
{
781+
public void B()
782+
{
783+
var v = new FooImp();
784+
var x = v.Value.Value;
785+
}
786+
}
787+
}";
788+
var diagnostics = GetSortedDiagnostics(new[] { test }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer());
789+
Assert.AreEqual("ChainedWrapper", diagnostics.Single().Descriptor.Id);
790+
}
791+
[Test]
792+
[Category("ChainedWrappers")]
793+
public void InterfaceContainsInterfaceType_Property_ReverseAssignment()
794+
{
795+
var test = @"namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
796+
{
797+
public interface ISafeComWrapper
798+
{
799+
FooImp Value { get; set; }
800+
}
801+
802+
public abstract class Foo : ISafeComWrapper
803+
{
804+
public virtual FooImp Value
805+
{
806+
get => new FooImp();
807+
set => new FooImp().Value = value;
808+
}
809+
}
810+
811+
public class FooImp : Foo
812+
{
813+
public override FooImp Value => base.Value;
814+
}
815+
816+
public class D
817+
{
818+
public void B()
819+
{
820+
var v = new FooImp();
821+
v.Value.Value = new FooImp();
822+
}
823+
}
755824
}";
756825
var diagnostics = GetSortedDiagnostics(new[] { test }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer());
757826
Assert.AreEqual("ChainedWrapper", diagnostics.Single().Descriptor.Id);
@@ -785,4 +854,35 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
785854

786855
}
787856
}
857+
}
858+
859+
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract1
860+
{
861+
public interface ISafeComWrapper
862+
{
863+
FooImp Value { get; set; }
864+
}
865+
866+
public abstract class Foo : ISafeComWrapper
867+
{
868+
public virtual FooImp Value
869+
{
870+
get => new FooImp();
871+
set => new FooImp().Value = value;
872+
}
873+
}
874+
875+
public class FooImp : Foo
876+
{
877+
public override FooImp Value => base.Value;
878+
}
879+
880+
public class D
881+
{
882+
public void B()
883+
{
884+
var v = new FooImp();
885+
v.Value.Value = new FooImp();
886+
}
887+
}
788888
}

0 commit comments

Comments
 (0)