diff --git a/src/DynamicExpresso.Core/Identifier.cs b/src/DynamicExpresso.Core/Identifier.cs index 71581f91..85b95e16 100644 --- a/src/DynamicExpresso.Core/Identifier.cs +++ b/src/DynamicExpresso.Core/Identifier.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; @@ -56,7 +56,9 @@ internal MethodGroupExpression(Delegate overload) internal void AddOverload(Delegate overload) { - _overloads.Add(overload); + // don't register the same overload twice + if (_overloads.IndexOf(overload) == -1) + _overloads.Add(overload); } } } diff --git a/test/DynamicExpresso.UnitTest/VariablesTest.cs b/test/DynamicExpresso.UnitTest/VariablesTest.cs index 75ba1d21..3b70e146 100644 --- a/test/DynamicExpresso.UnitTest/VariablesTest.cs +++ b/test/DynamicExpresso.UnitTest/VariablesTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using NUnit.Framework; using System.Linq.Expressions; using DynamicExpresso.Exceptions; @@ -140,6 +140,17 @@ public void Keywords_with_delegate() Assert.AreEqual(9.0, target.Eval("pow(3, 2)")); } + [Test] + public void Keywords_with_same_overload_twice() + { + Func pow = (x, y) => Math.Pow(x, y); + var target = new Interpreter() + .SetFunction("pow", pow) + .SetFunction("pow", pow); + + Assert.AreEqual(9.0, target.Eval("pow(3, 2)")); + } + [Test] public void Keywords_with_invalid_delegate_call() {