question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throw error when parsing the method with default parameters in v2.5.0

See original GitHub issue

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 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:closed
  • Created 2 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
metoulecommented, May 24, 2021

@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 the Delegate. Method property and the Invoke method of the delegate type were different.

I fixed the issue via #145.

2reactions
metoulecommented, May 22, 2021

Yes, that seems like a side effect of my changes. I’ll have a look at it!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found