Skip to content

Commit

Permalink
Fix broken lambda parsing. (#198)
Browse files Browse the repository at this point in the history
Fix #197
  • Loading branch information
metoule authored Dec 6, 2021
1 parent ae65ecb commit 83dc6e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DynamicExpresso.Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,10 @@ private bool TryParseKnownType(string name, out Type type)
// we found a known type identifier, check if it has some modifiers
private Type ParseTypeModifiers(Type type)
{
// type modifiers require the base type to be known
if (type == null)
return null;

var errorPos = _token.pos;
if (_token.id == TokenId.Question)
{
Expand Down
20 changes: 20 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ public void GitHub_Issue_169_quatro()
Assert.AreEqual("56", result);
}

[Test]
public void GitHub_Issue_197()
{
var interpreterWithLambdas = new Interpreter(InterpreterOptions.DefaultCaseInsensitive | InterpreterOptions.LambdaExpressions);
var interpreterWithoutLambdas = new Interpreter(InterpreterOptions.DefaultCaseInsensitive);

var stringExpression = "booleanValue ? someStringValue : \".\"";
var parameters = new List<Parameter>
{
new Parameter($"someStringValue", typeof(string), $"E33"),
new Parameter("booleanValue", typeof(bool), true)
};

var expressionWithoutLambdas = interpreterWithoutLambdas.Parse(stringExpression, typeof(void), parameters.ToArray());
Assert.AreEqual("E33", expressionWithoutLambdas.Invoke(parameters.ToArray()));

var expressionWithLambdas = interpreterWithLambdas.Parse(stringExpression, typeof(void), parameters.ToArray());
Assert.AreEqual("E33", expressionWithLambdas.Invoke(parameters.ToArray()));
}

[Test]
public void GitHub_Issue_185()
{
Expand Down

0 comments on commit 83dc6e4

Please sign in to comment.