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

Parsing exception while using 'as' operator #287

Closed
pawel1708hp opened this issue Jun 7, 2023 · 7 comments · Fixed by #289
Closed

Parsing exception while using 'as' operator #287

pawel1708hp opened this issue Jun 7, 2023 · 7 comments · Fixed by #289

Comments

@pawel1708hp
Copy link

I'm trying to use following expression:

string.IsNullOrEmpty(variable as string)

but it results with exception: DynamicExpresso.Exceptions.ParseException: ')' or ',' expected (at index 40).

Adding extra parenthesis as message suggests solves the issue, but the expression is obviously wrong then
string.IsNullOrEmpty(variable as string))

Seems there is something wrong with parser.

@metoule
Copy link
Contributor

metoule commented Jun 7, 2023

I think we don't support dynamic casts yet (the expr as Type expression). PRs welcome :)

@pawel1708hp
Copy link
Author

Well, according to documentation it is supported ;)
image

@IAMJDA
Copy link

IAMJDA commented Jun 8, 2023

We have the exact issue since upgrading to a newer version. Expressions which worked before, now break.

@davideicardi
Copy link
Member

It could be a regression. could you help us by telling us from which version it stopped working?

@IAMJDA
Copy link

IAMJDA commented Jun 9, 2023

Before: 2.8.1.0
After: 2.10.0.0

Test for As_Operator:
Assert.AreEqual(string.IsNullOrEmpty(a as string), target.Eval("string.IsNullOrEmpty(a as string)"));

@IAMJDA
Copy link

IAMJDA commented Jun 9, 2023

Manual bisect:

  • 2.9.5 fails
  • 2.9.4 works

#178 seems to be to blame

@metoule
Copy link
Contributor

metoule commented Jun 10, 2023

@IAMJDA thanks for narrowing it down! It's indeed a regression in the way the types are parsed: we don't reset the parser position properly if the type has no modifier. I'll need to ensure it's working for all the possible type modifiers. For example:

string?
string?[]
string?[][]
IEnumerable<string>
IEnumerable<string?[]>?[]

but it shouldn't take too long 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants