Skip to content

Commit 08fc6fe

Browse files
committed
bail out given class member call
1 parent 2f1dfb4 commit 08fc6fe

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ private bool IsAssignedByRefArgument(Declaration enclosingProcedure, IdentifierR
7070
var procedure = State.DeclarationFinder.MatchName(procedureName)
7171
.Where(p => AccessibilityCheck.IsAccessible(enclosingProcedure, p))
7272
.SingleOrDefault(p => !p.DeclarationType.HasFlag(DeclarationType.Property) || p.DeclarationType.HasFlag(DeclarationType.PropertyGet));
73+
if (procedure?.ParentScopeDeclaration is ClassModuleDeclaration)
74+
{
75+
// we can't know that the member is on the class' default interface
76+
return false;
77+
}
78+
7379
var parameters = State.DeclarationFinder.Parameters(procedure);
7480

7581
ParameterDeclaration parameter;

RubberduckTests/Inspections/NonReturningFunctionInspectionTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,35 @@ End Sub
217217
}
218218
}
219219

220+
[Test]
221+
[Category("Inspections")]
222+
public void NonReturningFunction_NoResult_GivenClassMemberCall()
223+
{
224+
const string code = @"
225+
Public Function Foo() As Boolean
226+
With New Class1
227+
.ByRefAssign Foo
228+
End With
229+
End Function
230+
";
231+
const string classCode = @"
232+
Public Sub ByRefAssign(ByRef b As Boolean)
233+
End Sub
234+
";
235+
var builder = new MockVbeBuilder();
236+
builder.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
237+
.AddComponent("TestModule1", ComponentType.StandardModule, code)
238+
.AddComponent("Class1", ComponentType.ClassModule, classCode);
239+
var vbe = builder.Build();
240+
using (var state = MockParser.CreateAndParse(vbe.Object))
241+
{
242+
var inspection = new NonReturningFunctionInspection(state);
243+
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
244+
245+
Assert.AreEqual(0, inspectionResults.Count());
246+
}
247+
}
248+
220249
[Test]
221250
[Category("Inspections")]
222251
public void NonReturningFunction_NoResult_GivenByRefAssignment_WithNamedArgument()

0 commit comments

Comments
 (0)