Skip to content

Commit 6071768

Browse files
committed
Fixed warnings. Fixed negate in LambdaInvokeExpression.
1 parent 83e5a17 commit 6071768

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

src/EPPlus/ExcelStyles.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ private void SetStyleCells(StyleBase sender, StyleChangeEventArgs e, ExcelAddres
557557
}
558558
else
559559
{
560-
int r = 0, c = col;
560+
int c = col;
561561
if ( ws.ColumnLookup.TryGetExcelColumn(c, out ExcelColumn colVal) )
562562
{
563563
c = colVal.ColumnMin;

src/EPPlus/FormulaParsing/DependencyChain/RpnFormulaExecution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
12751275
}
12761276
}
12771277
}
1278-
catch(Exception exp)
1278+
catch
12791279
{
12801280
f._expressionStack.Push(ErrorExpression.ValueError);
12811281
}

src/EPPlus/FormulaParsing/Excel/Functions/RefAndLookup/LookupUtils/LookupBinarySearch.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Date Author Change
1111
22/3/2023 EPPlus Software AB EPPlus v7
1212
*************************************************************************************************/
1313

14-
using OfficeOpenXml.Utils;
15-
using OfficeOpenXml.Utils;
1614
using System.Collections.Generic;
1715

1816
namespace OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup.LookupUtils

src/EPPlus/FormulaParsing/FormulaExpressions/LambdaFunctionExpression.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ internal class LambdaFunctionExpression : VariableFunctionExpression
2222
{
2323
internal override bool IsLambda => true;
2424
internal override bool HandlesVariables => true;
25-
private List<Token> _lambdaTokens;
2625

2726
internal LambdaFunctionExpression(string tokenValue, ParsingContext ctx, int pos) : base(tokenValue, ctx, pos)
2827
{

src/EPPlus/FormulaParsing/FormulaExpressions/LambdaInvokeExpression.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal LambdaInvokeExpression(LambdaCalculationExpression exp, ParsingContext
2323
this._function = new Lambda();
2424
}
2525

26-
private bool _negate = false;
26+
// private bool _negate = false;
2727
private readonly LambdaCalculationExpression _calculationExpression;
2828
private readonly List<CompileResult> _lambdaArguments = new List<CompileResult>();
2929

@@ -52,14 +52,25 @@ public override CompileResult Compile()
5252
var arg = _lambdaArguments[i];
5353
calculator.SetVariableValue(i, arg.Result, arg.DataType, Context, arg.Address);
5454
}
55+
5556
var result = calculator.Execute(Context);
56-
return result;
57-
}
5857

59-
public override Expression Negate()
60-
{
61-
_negate = !_negate;
62-
return this;
58+
if (_negate != 0)
59+
{
60+
if (result.IsNumeric == false)
61+
{
62+
if (Context.Debug)
63+
{
64+
var msg = string.Format("Trying to negate a non-numeric value ({0}) in a lambda function '{1}'",
65+
result.Result, nameof(_function));
66+
Context.Configuration.Logger.Log(Context, msg);
67+
}
68+
return new CompileResult(ExcelErrorValue.Create(eErrorType.Value), DataType.ExcelError);
69+
}
70+
return new CompileResult(result.ResultNumeric * _negate, result.DataType);
71+
}
72+
73+
return result;
6374
}
6475

6576
internal override void OnDispose()

src/EPPlus/FormulaParsing/ParsingContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public ExcelWorksheet CurrentWorksheet
166166
}
167167

168168
internal RemoteCallManager RemoteCallManager { get; }= new RemoteCallManager();
169+
/// <summary>
169170
/// Calculation options/parameters set for the Calculate call.
170171
/// </summary>
171172
public ExcelCalculationOption CalcOption { get; set; }

0 commit comments

Comments
 (0)