Skip to content

Referencing property of property can cause unwanted exception #135

Open
@AttilaSzobonya

Description

@AttilaSzobonya

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions