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

Indexer ambiguity when inherited class replaces parent's indexer with new keyword #305

Closed
denbell5 opened this issue Apr 9, 2024 · 0 comments · Fixed by #306
Closed
Labels

Comments

@denbell5
Copy link
Contributor

denbell5 commented Apr 9, 2024

Hello!

First of all, thanks to all of the contributors for this project.

This is a very rare case, but it exists in our project. The issue happens when descendant class overrides indexer with new keyword and sets a different return type. In this case, Parser finds two applicable methods, calls MethodHasPriority, and then fails here because MethodBase is null for IndexerData.

Unit test code to reproduce:

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

public class B : A
{
	public new int this[int index] => 25;
}

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

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

I investigated the code, and, if this is ok, I would like to create a pull request with suggested solution for this issue.

denbell5 added a commit to denbell5/DynamicExpresso that referenced this issue Apr 9, 2024
@denbell5 denbell5 mentioned this issue Apr 9, 2024
davideicardi pushed a commit that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants