zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
459 stars 86 forks source link

Ambiguous match? #93

Closed cesaryuan closed 3 years ago

cesaryuan commented 3 years ago
new EvalContext().Execute(@"""test"".IndexOf('e', 1);");

Hi, the above sentence throws error like below. But it works in VS. Could you check it? Thank you!

Z.Expressions.Compiler.Shared.EvalException
  HResult=0x80131500
  Message=Oops! Ambiguous match found for: 'IndexOf'. The error occurred for expression "." at position 6 near ".IndexOf('e', 1);".
  Source=Z.Expressions.Eval
  StackTrace:
   at .(ExpressionScope , Expression , Type , String , List`1 , Boolean , List`1 , SyntaxNode , Expression& )
   at .(ExpressionScope , SyntaxNode , Type , Expression , List`1 )
   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.Execute[TResult](String code)
   at SomeTest.Program.Main(String[] args) in E:\Desktop\Program\C#\SomeTest\Program.cs:line 49

  此异常最初是在此调用堆栈中引发的: 
    [外部代码]
    SomeTest.Program.Main(string[]) (位于 Program.cs 中)
JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

Thank you, we will look at it.

This is probably causing because we also support single quote to be a string like this abc and not only a character.

We will look at how we could improve the logic.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

The v4.0.31 is finally released.

We improved our code to better handle Ambiguous matches for multiple scenarios such as this one.

Let me know if everything is now working correctly with this scenario.

Best Regards,

Jon

cesaryuan commented 3 years ago

@JonathanMagnan Thank you so much! But I update to the v4.0.31 and it still throw the same errors.

static void Main(string[] args)
{
    new EvalContext().Execute(@"""test"".IndexOf('e', 1);");
}
Z.Expressions.Compiler.Shared.EvalException
  HResult=0x80131500
  Message=Oops! Ambiguous match found for: 'IndexOf'. The error occurred for expression "." at position 6 near ".IndexOf('e', 1);".
  Source=Z.Expressions.Eval
  StackTrace:
   at .(ExpressionScope , Expression , Type , String , List`1 , Boolean , List`1 , SyntaxNode , Expression& )
   at .(ExpressionScope , SyntaxNode , Type , Expression , List`1 )
   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.Execute[TResult](String code)
   at SomeTest.Program.Main(String[] args) in E:\Desktop\Program\C#\SomeTest\Program.cs:line 63

  此异常最初是在此调用堆栈中引发的: 
    [外部代码]
    SomeTest.Program.Main(string[]) (位于 Program.cs 中)

image

JonathanMagnan commented 3 years ago

No problem, we will look at it again.

JonathanMagnan commented 3 years ago

Hello @cesaryuan ,

The v4.0.32 has been released.

Could you try this one and let us know if everything is working correctly this time?

Best Regards,

Jon

cesaryuan commented 3 years ago

@JonathanMagnan It seems fixed. Thank you!