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

Seems doesn't support User-defined Implicit type conversion operators? #97

Open
cesaryuan opened this issue Mar 6, 2021 · 2 comments
Open
Assignees

Comments

@cesaryuan
Copy link

The following statement will report an error.

using Newtonsoft.Json.Linq;

static void Main(string[] args)
{
    var context = new EvalContext();
    context.RegisterType(typeof(JArray));
    context.Execute(@"new JArray().Contains(""D"")");
}

The error is as follows

Z.Expressions.Compiler.Shared.EvalException
  HResult=0x80131500
  Message=Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 12 near ".Contains(\"D\")".
  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 66

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

JArray.Contains(JToken T) only accepts JToken, so EvalContext considers No applicable member
But we know that Newtonsoft.Json.Linq defines implicit type conversion from String to JToken, and this statement works properly in VS.

@JonathanMagnan JonathanMagnan self-assigned this Mar 8, 2021
@JonathanMagnan
Copy link
Member

Hello @cesaryuan ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @cesaryuan ,

Just to let you know that there is currently no short-term plan to make it works.

We will look again in around 2-3 months to add better support to implicit type, but at this moment, this will be a limitation of our library.

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

No branches or pull requests

2 participants