Skip to content

Commit 942b5f7

Browse files
author
Andrin Meier
committed
fix binary plus operator handling of Empty and String
1 parent 68265a9 commit 942b5f7

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Rubberduck.Parsing/Preprocessing/BinaryPlusExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override IValue Evaluate()
1919
{
2020
return null;
2121
}
22-
if (left.ValueType == ValueType.String)
22+
if (left.ValueType == ValueType.String || right.ValueType == ValueType.String)
2323
{
2424
return new StringValue(left.AsString+ right.AsString);
2525
}

Rubberduck.Parsing/Preprocessing/NameExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public NameExpression(
1616
public override IValue Evaluate()
1717
{
1818
var identifier = _identifier.Evaluate().AsString;
19-
// Special case, identifier that does not exist is VBAEmpty.
19+
// Special case, identifier that does not exist is Empty.
2020
// Could add them to the symbol table, but since they are all constants
2121
// they never change anyway.
2222
if (!_symbolTable.HasSymbol(identifier))

RubberduckTests/Preprocessing/VBAPreprocessorVisitorTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ public void TestPlusOperator()
9494
#Const c = True + False + True
9595
#Const d = Nothing
9696
#Const e = ""5"" + ""4""
97+
#Const f = Empty + Empty
98+
#Const g = Empty + ""a""
99+
#Const h = ""a"" + Empty
97100
";
98101
var result = Preprocess(code);
99102
Assert.AreEqual(1544.242m, result.Item1.Get("a").AsDecimal);
100103
Assert.AreEqual(new DateTime(2298, 3, 7), result.Item1.Get("b").AsDate);
101104
Assert.AreEqual(-2m, result.Item1.Get("c").AsDecimal);
102105
Assert.AreEqual(null, result.Item1.Get("d"));
103106
Assert.AreEqual("54", result.Item1.Get("e").AsString);
107+
Assert.AreEqual(0m, result.Item1.Get("f").AsDecimal);
108+
Assert.AreEqual("a", result.Item1.Get("g").AsString);
109+
Assert.AreEqual("a", result.Item1.Get("h").AsString);
104110
}
105111

106112
[TestMethod]

0 commit comments

Comments
 (0)