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.

Parser.MethodHasPriority regression

See original GitHub issue

Method Parser.MethodHasPriority causes a regression in my tests. None of two possible methods is chosen.

methods:

0: {System.Collections.Generic.IEnumerable`1[System.Object] Select[TSource] System.Collections.Generic.IEnumerable`1[TSource], System.String)}
1: {System.Collections.Generic.IEnumerable`1[System.Object] Select(System.Collections.IEnumerable, System.String)}

and args passed:

0: {System.Collections.Generic.List`1[System.Object]}
1: {System.String}

See following test example…

namespace EvalTest
{
    using System.Collections;
    using System.Collections.Generic;
    using DynamicExpresso;
    using NUnit.Framework;

    [TestFixture]
    public class EvalTest
    {
        private Interpreter interpreter = new Interpreter();

        [OneTimeSetUp]
        public void Setup()
        {
            this.interpreter.Reference(typeof(Utils));
        }

        [Test]
        public void EvaluateTest()
        {
            var list = new[] { 1, 2, 3 };
            Assert.DoesNotThrow(() => { this.Evaluate("Utils.Array(1, 2, 3)"); });
            Assert.DoesNotThrow(() => { this.Evaluate("Utils.Select(Utils.Array(\"a\", \"b\"), \"x+x\")"); });
        }

        private object Evaluate(string expression, params Parameter[] parameters)
        {
            return this.interpreter.Parse(expression, parameters).Invoke(parameters);
        }
    }

    public class Utils
    {
        public static List<T> Array<T>(IEnumerable<T> collection)
        {
            return new List<T>(collection);
        }

        public static List<dynamic> Array(params dynamic[] array)
        {
            return Array((IEnumerable<dynamic>)array);
        }

        public static IEnumerable<dynamic> Select<TSource>(IEnumerable<TSource> collection, string expression)
        {
            return new List<dynamic>();
        }

        public static IEnumerable<dynamic> Select(IEnumerable collection, string expression)
        {
            return new List<dynamic>();
        }
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
metoulecommented, Nov 23, 2021

@davideicardi no, it doesn’t solve the issue; I still have to fix the MethodHasPriority bug. It’s a bit tricky because I have to handle both the fix for this bug, while not breaking the lambda expression support.

PR #192 is not really needed to fix this bug, but I found it weird to use dynamic instead of generics, which is how I realized that it was not possible to use generics with params array.

@waclaw66 Utils.Array was indeed ok, but you’ll now be able to use generics to have a more strongly typed List:

private static class Utils
{
  public static List<T> Array<T>(params T[] array)
  {
    return new List<T>(array);
  }
}
1reaction
metoulecommented, Nov 23, 2021

Note that the issue occurs because the Select method has two overloads that clash with the current resolution; removing either overload should solve the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An Improved Kriging Model based on Differential Evolution
Abstract. Kriging model is a commonly interpolate approximation method which is widely used in the computer simulation in the past decade. The fitting....
Read more >
pickle — Python object serialization | Docs4dev
The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a ...
Read more >
Annual Research Report
access method has priority but other methods with the applicability to each unit ... Straight line shows regression ... Heating Furnace for Thermal...
Read more >
2015-December.txt - Python mailing list
+ +- Issue #25555: Fix parser and AST: fill lineno and col_offset of ... + +- Issue #25446: Fix regression in smtplib's AUTH...
Read more >
berberine combined treatment: Topics by ...
Partial least square regression models based on these 268 OTUs were established ... so we can say that this method has priority compared...
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