Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentiva authored Sep 14, 2023
1 parent a199778 commit 87182e7
Show file tree
Hide file tree
Showing 2 changed files with 21 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
20 changes: 20 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,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 = Path.Combine;
evaluator.SetFunction("PathCombine", pathCombine);

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

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

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

internal static class GithubIssuesTestExtensionsMethods
Expand Down

0 comments on commit 87182e7

Please sign in to comment.