Skip to content

Commit 18dcb0b

Browse files
committed
Fix failing tests. Add new test for field length statements.
1 parent 20c1ab7 commit 18dcb0b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
119119
return new SimpleNameDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, Identifier.GetName(expression.identifier()), statementContext);
120120
}
121121

122+
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.IdentifierValueContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
123+
{
124+
return new SimpleNameDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, Identifier.GetName(expression), statementContext);
125+
}
126+
122127
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.MemberAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
123128
{
124129
dynamic lExpression = expression.lExpression();

RubberduckTests/Grammar/ResolverTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,26 @@ End Sub
19571957
Assert.AreEqual(4, declaration.References.Count());
19581958
}
19591959

1960+
[TestMethod]
1961+
public void FieldLengthStmt_IsReferenceToLocalVariable()
1962+
{
1963+
// arrange
1964+
var code = @"
1965+
Public Sub Test()
1966+
Const Len As Integer = 4
1967+
Dim a As String * Len
1968+
End Sub
1969+
";
1970+
// act
1971+
var state = Resolve(code);
1972+
1973+
// assert
1974+
var declaration = state.AllUserDeclarations.Single(item =>
1975+
item.DeclarationType == DeclarationType.Constant && item.IdentifierName == "Len");
1976+
1977+
Assert.AreEqual(1, declaration.References.Count());
1978+
}
1979+
19601980
// Ignored because handling forms/hierarchies is an open issue.
19611981
[Ignore]
19621982
[TestMethod]

0 commit comments

Comments
 (0)