Throw error when parsing the method with default parameters in v2.5.0
See original GitHub issueHello, I have written a little test, it will pass in v2.4.1
and failed in v2.5.0
. But I can not find any breaking change in the release log,
Is this a bug or am I missing something? Thank you!
Test case:
private delegate bool GFunction(string arg = null);
[Fact]
public void TestParseGFunction()
{
static bool GetGFunction(string arg = null)
{
return arg is not null;
};
var interpreter = new Interpreter();
interpreter.SetFunction("GFunction", (GFunction) GetGFunction);
interpreter.SetVariable("arg", "arg");
Assert.True((bool) interpreter.Eval("GFunction(arg)"));
Assert.False((bool) interpreter.Eval("GFunction()"));
}
Failed information:
DynamicExpresso.Exceptions.ParseException
Argument list incompatible with delegate expression (at index 0).
at DynamicExpresso.Parsing.Parser.ParseMethodGroupInvocation(MethodGroupExpression methodGroup, Int32 errorPos)
at DynamicExpresso.Parsing.Parser.ParseUnary()
at DynamicExpresso.Parsing.Parser.ParseMultiplicative()
at DynamicExpresso.Parsing.Parser.ParseAdditive()
at DynamicExpresso.Parsing.Parser.ParseTypeTesting()
at DynamicExpresso.Parsing.Parser.ParseComparison()
at DynamicExpresso.Parsing.Parser.ParseLogicalAnd()
at DynamicExpresso.Parsing.Parser.ParseLogicalXor()
at DynamicExpresso.Parsing.Parser.ParseLogicalOr()
at DynamicExpresso.Parsing.Parser.ParseConditionalAnd()
at DynamicExpresso.Parsing.Parser.ParseConditionalOr()
at DynamicExpresso.Parsing.Parser.ParseConditional()
at DynamicExpresso.Parsing.Parser.ParseAssignment()
at DynamicExpresso.Parsing.Parser.ParseExpressionSegment()
at DynamicExpresso.Parsing.Parser.ParseExpressionSegment(Type returnType)
at DynamicExpresso.Parsing.Parser.Parse()
at DynamicExpresso.Interpreter.ParseAsLambda(String expressionText, Type expressionType, Parameter[] parameters)
at DynamicExpresso.Interpreter.Parse(String expressionText, Type expressionType, Parameter[] parameters)
at DynamicExpresso.Interpreter.Eval(String expressionText, Type expressionType, Parameter[] parameters)
at DynamicExpresso.Interpreter.Eval(String expressionText, Parameter[] parameters)
at NetCasbin.UnitTest.UtilityTest.TestParseGFunction() in C:\Users\Sagilio\source\repos\OnWork\Casbin\Casbin.NET\NetCasbin.UnitTest\UtilityTest.cs:line 26
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Throw error when parsing the method with default ...
Hello, I have written a little test, it will pass in v2.4.1 and failed in v2.5.0. But I can not find any breaking...
Read more >Parameter to control whether to throw an exception or ...
I often come across methods/functions which have an additional boolean parameter which controls whether an exception is thrown on failure, or ...
Read more >powershell v2 function, how to have a default value for ...
You could do something like: function foo { param ($int=-1,[string]$str="''") if ($int.gettype().Name -eq 'String') { $str = $int; $int = -1 } ...
Read more >Default parameters - JavaScript - MDN Web Docs - Mozilla
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Guide to Spring Boot REST API Error Handling
Implement consumer-friendly support to a Spring Boot REST API by hiding implementation details and delivering easily digestible fields.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Sagilio version 2.5.0 includes a fix for #82 to allow the registration of multiple delegates with the same name, to simulate function overloads. To do that, I changed the way delegates are resolved when set via
SetFunction
. I introduced a regression, for which I apologize: I didn’t realize that theDelegate. Method
property and theInvoke
method of the delegate type were different.I fixed the issue via #145.
Yes, that seems like a side effect of my changes. I’ll have a look at it!