Skip to content

Commit

Permalink
Fix Issue #295 (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentiva authored Oct 3, 2023
1 parent a199778 commit 2696232
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DynamicExpresso.Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,7 @@ private static Expression PromoteExpression(Expression expr, Type type, bool exa
return Expression.Convert(expr, genericType);
}

if (IsCompatibleWith(expr.Type, type))
if (IsCompatibleWith(expr.Type, type) || expr is DynamicExpression)
{
if (type.IsValueType || exact)
{
Expand Down
21 changes: 21 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Dynamic;

// ReSharper disable SpecifyACultureInStringConversionExplicitly

Expand Down Expand Up @@ -772,6 +773,26 @@ public void GitHub_Issue_292()

Assert.IsTrue(testnpcs.All(n => n.money == 10));
}

[Test]
public void GitHub_Issue_295() {
var evaluator = new Interpreter();

// create path helper functions in expressions...
Func<string, string, string> pathCombine = string.Concat;
evaluator.SetFunction("StringConcat", pathCombine);

// add a GlobalSettings dynamic object...
dynamic globalSettings = new ExpandoObject();
globalSettings.MyTestPath = "C:\\delme\\";
evaluator.SetVariable("GlobalSettings", globalSettings);

var works = (string) evaluator.Eval("StringConcat((string)GlobalSettings.MyTestPath,\"test.txt\")");
Assert.That(works, Is.EqualTo("C:\\delme\\test.txt"));

var doesntWork = (string) evaluator.Eval("StringConcat(GlobalSettings.MyTestPath,\"test.txt\")");
Assert.That(doesntWork, Is.EqualTo("C:\\delme\\test.txt"));
}
}

internal static class GithubIssuesTestExtensionsMethods
Expand Down

0 comments on commit 2696232

Please sign in to comment.