Skip to content

Commit ef11a05

Browse files
committed
Consider More than just ClassModules for MemberNotOnInterface
fixes #2189
1 parent abc2b53 commit ef11a05

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

Rubberduck.Inspections/Concrete/MemberNotOnInterfaceInspection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2323

2424
var targets = Declarations.Where(decl => decl.AsTypeDeclaration != null &&
2525
!decl.AsTypeDeclaration.IsUserDefined &&
26-
decl.AsTypeDeclaration.DeclarationType == DeclarationType.ClassModule &&
26+
decl.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule) &&
2727
((ClassModuleDeclaration)decl.AsTypeDeclaration).IsExtensible)
2828
.SelectMany(decl => decl.References).ToList();
29-
3029
return from access in unresolved
3130
let callingContext = targets.FirstOrDefault(usage => usage.Context.Equals(access.CallingContext))
3231
where callingContext != null
3332
select new DeclarationInspectionResult(this,
34-
string.Format(InspectionsUI.MemberNotOnInterfaceInspectionResultFormat, access.IdentifierName, callingContext.Declaration.AsTypeDeclaration.IdentifierName),
35-
access);
33+
string.Format(InspectionsUI.MemberNotOnInterfaceInspectionResultFormat, access.IdentifierName, callingContext.Declaration.AsTypeDeclaration.IdentifierName),
34+
access);
3635
}
3736
}
3837
}

Rubberduck.Parsing/Symbols/IdentifierReferenceResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private void ResolveDefault(
174174
{
175175
var lexpression = expression as VBAParser.LExpressionContext
176176
?? expression.GetChild<VBAParser.LExpressionContext>(0)
177-
?? (expression as VBAParser.LExprContext
177+
?? (expression as VBAParser.LExprContext
178178
?? expression.GetChild<VBAParser.LExprContext>(0))?.lExpression();
179179

180180
if (lexpression != null)

RubberduckTests/Inspections/MemberNotOnInterfaceInspectionTests.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,67 @@ Dim dict As Dictionary
265265
Assert.IsFalse(inspectionResults.Any());
266266
}
267267
}
268+
269+
[TestMethod]
270+
[DeploymentItem(@"Testfiles\")]
271+
[TestCategory("Inspections")]
272+
public void MemberNotOnInterface_CatchesInvalidUseOfMember()
273+
{
274+
const string userForm1Code = @"
275+
Private _fooBar As String
276+
277+
Public Property Let FooBar(value As String)
278+
_fooBar = value
279+
End Property
280+
281+
Public Property Get FooBar() As String
282+
FooBar = _fooBar
283+
End Property
284+
";
285+
286+
const string analyzedCode = @"Option Explicit
287+
288+
Sub FizzBuzz()
289+
290+
Dim bar As UserForm1
291+
Set bar = New UserForm1
292+
bar.FooBar = ""FooBar""
293+
294+
Dim foo As UserForm
295+
Set foo = New UserForm1
296+
foo.FooBar = ""BarFoo""
297+
298+
End Sub
299+
";
300+
var mockVbe = new MockVbeBuilder();
301+
var projectBuilder = mockVbe.ProjectBuilder("testproject", ProjectProtection.Unprotected);
302+
projectBuilder.MockUserFormBuilder("UserForm1", userForm1Code).MockProjectBuilder()
303+
.AddComponent("ReferencingModule", ComponentType.StandardModule, analyzedCode)
304+
//.AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel)
305+
.AddReference("MSForms", MockVbeBuilder.LibraryPathMsForms);
306+
307+
mockVbe.AddProject(projectBuilder.Build());
308+
309+
310+
var parser = MockParser.Create(mockVbe.Build().Object);
311+
312+
//parser.State.AddTestLibrary("Excel.1.8.xml");
313+
parser.State.AddTestLibrary("MSForms.2.0.xml");
314+
315+
parser.Parse(new CancellationTokenSource());
316+
if (parser.State.Status >= ParserState.Error)
317+
{
318+
Assert.Inconclusive("Parser Error");
319+
}
320+
321+
using (var state = parser.State)
322+
{
323+
var inspection = new MemberNotOnInterfaceInspection(state);
324+
var inspectionResults = inspection.GetInspectionResults();
325+
326+
Assert.IsTrue(inspectionResults.Any());
327+
}
328+
329+
}
268330
}
269331
}

0 commit comments

Comments
 (0)