Skip to content

Commit 96ce522

Browse files
author
Sébastien Geiser
committed
Correction collection/array indexing when OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = true (One more correction when #33)
1 parent 7e78bd1 commit 96ce522

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,13 @@ public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
15401540
.SetCategory("Options")
15411541
.SetCategory("Integer Numbers default types");
15421542

1543+
yield return new TestCaseData(evaluatorWithIntForceToDouble
1544+
, "(new string[] { \"Test\", \"Other\", \"Youhouhou\" })[1]")
1545+
.Returns("Other")
1546+
.SetCategory("Bug")
1547+
.SetCategory("Options")
1548+
.SetCategory("Integer Numbers default types");
1549+
15431550
#endregion
15441551

15451552
#region GenericTypes in onthefly events

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,9 @@ private bool EvaluateIndexing(string expr, string s, Stack<object> stack, ref in
24252425
ExpressionOperator op = indexingBeginningMatch.Length == 2 ? ExpressionOperator.IndexingWithNullConditional : ExpressionOperator.Indexing;
24262426
dynamic left = stack.Pop();
24272427

2428+
if (OptionForceIntegerNumbersEvaluationsAsDoubleByDefault && right is double && Regex.IsMatch(innerExp.ToString(), @"^\d+$"))
2429+
right = (int)right;
2430+
24282431
Match assignationOrPostFixOperatorMatch = null;
24292432

24302433
dynamic valueToPush = null;

0 commit comments

Comments
 (0)