We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Have a look at the following test cases
[TestMethod] [DataRow("#1", "a1", 1)] [DataRow("#2", "(a1)", 1)] [DataRow("#3", "(a1)+(a1)", 2)] [DataRow("#4", "(a1)+a1", 2)] [DataRow("#5", "(a1)-(a1)", 0)] [DataRow("#6", "(a1)-a1", 0)] public void TestSimpleFalseCastExpressions(string id, string expression, int expected) { var context = new EvalContext(); var types = new Dictionary<string, Type> { { "a1", typeof(double) }, }; var values = new Dictionary<object, double> { { "a1", 1.0 }, }; var compiled = context.Compile(expression, types); var result = compiled.Invoke(values); result.Should().Be(expected); }
The cases #5 and #6 fail with the following exception:
Test method EvalExpressionsTests.TestSimpleFalseCastExpressions threw exception: Z.Expressions.Compiler.Shared.EvalException: Oops! The type was not found.. The error occurred for expression "(" at position 0 near "(a1)-(a1)". at .(ExpressionScope , SyntaxNode , Expression , Boolean ) at .(ExpressionScope , SyntaxNode , Expression , Boolean ) at .(ExpressionScope , SyntaxNode , Expression , Boolean ) at Z.Expressions.CodeCompiler.CSharp.ExpressionParser.ParseSyntax(ExpressionScope scope, SyntaxNode node, Type resultType) at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean ) at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean ) at Z.Expressions.EvalContext.Compile(String code, IDictionary`2 parameterTypes) at EvalExpressionsTests.TestSimpleFalseCastExpressions(String id, String expression, Int32 expected) in EvalExpressionsTests.cs:line 141 at InvokeStub_EvalExpressionsTests.TestSimpleFalseCastExpressions(Object, Span`1) at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
My suspicion is that (a1) is (wrongly) interpreted as cast when followed by a - sign, because the - is interpreted as unary negation operator.
(a1)
-
I would expect the parser to be able to distinguish between a real cast and an expression in parens.
For example "(double) -1" should be identified as a cast, "(a1)-1" should be identified as a subtraction.
"(double) -1"
"(a1)-1"
The text was updated successfully, but these errors were encountered:
Hello @void80 ,
Thank you for reporting.
Your suspicion is probably 100% right. I remember we fixed a similar issue recently but slightly different #154 (he wanted to cast it on his side).
We will look at it.
Best Regards,
Jon
Sorry, something went wrong.
We've figured out that a downgrade to 6.0.1 works around the problem, in case this helps you. Best regards, Sebastian
JonathanMagnan
No branches or pull requests
Have a look at the following test cases
The cases #5 and #6 fail with the following exception:
My suspicion is that
(a1)
is (wrongly) interpreted as cast when followed by a-
sign, because the-
is interpreted as unary negation operator.I would expect the parser to be able to distinguish between a real cast and an expression in parens.
For example
"(double) -1"
should be identified as a cast,"(a1)-1"
should be identified as a subtraction.The text was updated successfully, but these errors were encountered: