Skip to content

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

@denbell5

Description

@denbell5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions