Skip to content

Commit 7e196a1

Browse files
authored
Merge pull request #4243 from comintern/issue3906
Fix association of property implementations to declaring interfaces
2 parents f1c1f0c + 531e6dd commit 7e196a1

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterCanBeByValInspection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ private IEnumerable<IInspectionResult> GetResults(Declaration[] declarations, De
9090
.ThenBy(t => t.Selection.StartColumn)
9191
.ToList();
9292

93+
//If you hit this assert, reopen https://github.com/rubberduck-vba/Rubberduck/issues/3906
94+
Debug.Assert(parametersAreByRef.Count == parameters.Count);
95+
9396
for (var i = 0; i < parameters.Count; i++)
9497
{
95-
//If you hit this assert, congratulations! you've found a test case for https://github.com/rubberduck-vba/Rubberduck/issues/3906
96-
//Please examine the code, and if possible, either fix the indexing on this or upload your failing code to the GitHub issue.
97-
Debug.Assert(parametersAreByRef.Count == parameters.Count);
9898
parametersAreByRef[i] = parametersAreByRef[i] &&
9999
!IsUsedAsByRefParam(declarations, parameters[i]) &&
100100
((VBAParser.ArgContext) parameters[i].Context).BYVAL() == null &&

Rubberduck.Refactorings/Common/DeclarationExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this I
417417
public static IEnumerable<Declaration> FindInterfaceImplementationMembers(this IEnumerable<Declaration> declarations, Declaration interfaceDeclaration)
418418
{
419419
return FindInterfaceImplementationMembers(declarations)
420-
.Where(m => m.IdentifierName == interfaceDeclaration.ComponentName + "_" + interfaceDeclaration.IdentifierName);
420+
.Where(m => m.DeclarationType == interfaceDeclaration.DeclarationType && m.IdentifierName ==
421+
interfaceDeclaration.ComponentName + "_" + interfaceDeclaration.IdentifierName);
421422
}
422423

423424
public static Declaration FindInterfaceMember(this IEnumerable<Declaration> declarations, Declaration implementation)

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<Compile Include="Mocks\MockExtentions.cs" />
120120
<Compile Include="Inspections\DefTypeStatementInspectionTests.cs" />
121121
<Compile Include="Inspections\InspectionProviderTests.cs" />
122+
<Compile Include="Symbols\DeclarationExtensionTests.cs" />
122123
<Compile Include="Symbols\ToVbExpressionTests.cs" />
123124
<Compile Include="UnitTesting\TestMethodTests.cs" />
124125
<Compile Include="VBEditor\Utility\DisposalActionContainerTests.cs" />
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using NUnit.Framework;
4+
using Rubberduck.Common;
5+
using Rubberduck.Parsing.Symbols;
6+
using Rubberduck.VBEditor;
7+
using Rubberduck.VBEditor.SafeComWrappers;
8+
using RubberduckTests.Mocks;
9+
10+
namespace RubberduckTests.Symbols
11+
{
12+
[TestFixture]
13+
public class DeclarationExtensionTests
14+
{
15+
[Test]
16+
[Category("Resolver")]
17+
public void FindInterfaceImplementationMembersMatchesDeclarationTypes()
18+
{
19+
var intrface =
20+
@"Option Explicit
21+
22+
Public Property Get Foo(Bar As Long) As Long
23+
End Property
24+
25+
Public Property Let Foo(Bar As Long, NewValue As Long)
26+
End Property
27+
";
28+
29+
var implementation =
30+
@"Option Explicit
31+
32+
Implements TestInterface
33+
34+
Private Property Get TestInterface_Foo(Bar As Long) As Long
35+
End Property
36+
37+
Private Property Let TestInterface_Foo(Bar As Long, RHS As Long)
38+
End Property
39+
";
40+
var vbe = new MockVbeBuilder()
41+
.ProjectBuilder("UnderTest", ProjectProtection.Unprotected)
42+
.AddComponent("TestInterface", ComponentType.ClassModule, intrface, new Selection(1, 1))
43+
.AddComponent("TestImplementation", ComponentType.ClassModule, implementation, new Selection(1, 1))
44+
.AddProjectToVbeBuilder()
45+
.Build();
46+
47+
var parser = MockParser.Create(vbe.Object);
48+
parser.Parse(new CancellationTokenSource());
49+
50+
var declarations = parser.State.DeclarationFinder.AllDeclarations.ToList();
51+
var declaration = declarations.Single(decl => decl.DeclarationType == DeclarationType.PropertyGet && decl.IdentifierName.Equals("Foo"));
52+
53+
var expected = declarations.Single(decl => decl.DeclarationType == DeclarationType.PropertyGet && decl.IdentifierName.Equals("TestInterface_Foo"));
54+
var actual = declarations.FindInterfaceImplementationMembers(declaration).ToList();
55+
var results = actual.Count;
56+
57+
Assert.AreEqual(1, results, "Expected {0} Declarations, received {1}", expected, results);
58+
Assert.AreEqual(expected, actual.First(), "Expected {0}, resolved to {1}", expected, actual);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)