Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer crash when a lambda parameter argument type can't be parsed #198

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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