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

Referencing property of property can cause unwanted exception #135

Open
AttilaSzobonya opened this issue May 26, 2022 · 0 comments
Open
Assignees
Labels

Comments

@AttilaSzobonya
Copy link
Contributor

AttilaSzobonya commented May 26, 2022

Hello! I don't really know how to name this issue, but I experience a bug, which can be easily reproduced as the following:

$ dotnet new console
$ dotnet add package CodingSeb.ExpressionEvaluator --version 1.5.0-alpha0004

then in the Program.cs write:

using CodingSeb.ExpressionEvaluator;

ExpressionEvaluator ee = new ExpressionEvaluator();

ee.Variables["A"] = new Dictionary<string, FileStream>();

System.Console.WriteLine(ee.Evaluate<bool>("A.TryGetValue(\"NotExist\", out FileStream fs) && fs.SafeFileHandle.IsAsync == true"));

executing this raises an exception saying:

Unhandled exception. CodingSeb.ExpressionEvaluator.ExpressionEvaluatorSyntaxErrorException: Invalid character [61:=]
   at CodingSeb.ExpressionEvaluator.ExpressionEvaluator.Evaluate(String expression)
   at CodingSeb.ExpressionEvaluator.ExpressionEvaluator.Evaluate[T](String expression)
   at Program.<Main>$(String[] args) in /home/itf/reproduce_bug/Program.cs:line 7

If I change the code to

System.Console.WriteLine(ee.Evaluate<bool>("A.TryGetValue(\"NotExist\", out FileStream fs) && fs.SafeFileHandle == true"));

it works perfectly. None of the types of the variables and properties matter here. It solely dependent on how many levels of reference I write. I realize there is an issue about logical operators not being short-circuit, but it has to be something else as it works well if I write zero or one property references, and it also needs the ==, != or possibly other operator to fail. (only checked for == and !=)

These also works:

fs.SafeFileHandle.ToString() == string.Empty
fs.SafeFileHandle.IsAsync

This however not:

fs.SafeFileHandle.IsAsync.ToString() == string.Empty

Can it be fixed? :)

P.S. I'm on .NET 6.0.202

@codingseb codingseb self-assigned this May 30, 2022
@codingseb codingseb added the bug label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants