Skip to content

Commit 213822f

Browse files
committed
Fix WriteOnlyPropertyInspection
It did not consider that there could be a getter in another module with the same name.
1 parent 8a992ee commit 213822f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/WriteOnlyPropertyInspection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected override bool IsResultDeclaration(Declaration declaration, Declaration
6565
|| declaration.Accessibility == Accessibility.Public
6666
|| declaration.Accessibility == Accessibility.Global)
6767
&& finder.MatchName(declaration.IdentifierName)
68+
.Where(otherDeclaration => otherDeclaration.QualifiedModuleName.Equals(declaration.QualifiedModuleName))
6869
.All(accessor => accessor.DeclarationType != DeclarationType.PropertyGet);
6970
}
7071

RubberduckTests/Inspections/WriteOnlyPropertyInspectionTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ Property Set Foo(value)
7474
Assert.AreEqual(0, InspectionResultsForModules(("MyClass", inputCode, ComponentType.ClassModule)).Count());
7575
}
7676

77+
[Test]
78+
[Category("Inspections")]
79+
public void WriteOnlyProperty_ReturnsResult_GetInOtherModule()
80+
{
81+
const string classCode =
82+
@"Property Let Foo(value)
83+
End Property";
84+
85+
const string otherClassCode =
86+
@"Property Get Foo()
87+
End Property";
88+
89+
var inspectionResults = InspectionResultsForModules(
90+
("MyClass", classCode, ComponentType.ClassModule),
91+
("MyOtherClass", otherClassCode, ComponentType.ClassModule));
92+
93+
Assert.AreEqual(1, inspectionResults.Count());
94+
}
95+
7796
[Test]
7897
[Category("Inspections")]
7998
public void WriteOnlyProperty_Ignored_DoesNotReturnResult()

0 commit comments

Comments
 (0)