Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #305 #306

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/DynamicExpresso.Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,10 @@ private static bool MethodHasPriority(Expression[] args, MethodData method, Meth
if (better)
return true;

if (!method.MethodBase.IsGenericMethod && otherMethod.MethodBase.IsGenericMethod)
if (method.MethodBase != null &&
otherMethod.MethodBase != null &&
!method.MethodBase.IsGenericMethod &&
otherMethod.MethodBase.IsGenericMethod)
return true;

if (!method.HasParamsArray && otherMethod.HasParamsArray)
Expand All @@ -2721,6 +2724,19 @@ private static bool MethodHasPriority(Expression[] args, MethodData method, Meth
if (method.HasParamsArray && otherMethod.HasParamsArray && method.Parameters.Length > otherMethod.Parameters.Length)
return true;

if (method is IndexerData indexer && otherMethod is IndexerData otherIndexer)
{
var declaringType = indexer.Indexer.DeclaringType;
var otherDeclaringType = otherIndexer.Indexer.DeclaringType;

var isOtherIndexerIsInParentType = otherDeclaringType.IsAssignableFrom(declaringType);
if (isOtherIndexerIsInParentType)
{
var isIndexerIsInDescendantType = !declaringType.IsAssignableFrom(otherDeclaringType);
return isIndexerIsInDescendantType;
}
}

return better;
}

Expand Down
26 changes: 26 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,32 @@ public void GitHub_Issue_295() {
var doesntWork = (string) evaluator.Eval("StringConcat(GlobalSettings.MyTestPath,\"test.txt\")");
Assert.That(doesntWork, Is.EqualTo("C:\\delme\\test.txt"));
}

#region GitHub_Issue_305

public class _305_A
{
public string this[int index] => "some string";
}

public class _305_B : _305_A
{
public new int this[int index] => 25;
}

[Test]
public void GitHub_Issue_305()
{
var b = new _305_B();

var interpreter = new Interpreter();
var lambda = interpreter.Parse("this[0]", new Parameter("this", b));
var res = lambda.Invoke(b);

Assert.AreEqual(25, res);
}

#endregion
}

internal static class GithubIssuesTestExtensionsMethods
Expand Down
Loading