Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdebad7

Browse files
committed
Added test_public_inherited_overloaded_indexer
1 parent f0a4019 commit bdebad7

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/runtime/methodbinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
837837
{
838838
value.Append($" for {methodinfo[0].Name}");
839839
}
840-
else if (list.Count > 0 && list[0].Name != null)
840+
else if (list.Count > 0 && list[0].Valid)
841841
{
842-
value.Append($" for {list[0].Name}");
842+
value.Append($" for {list[0].Value.Name}");
843843
}
844844

845845
value.Append(": ");

src/testing/indexertest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ public interface IIndexer
427427

428428
public interface IInheritedIndexer : IIndexer { }
429429

430-
public class InterfaceInheritedIndexerTest :IndexerBase, IInheritedIndexer {
430+
public class InterfaceInheritedIndexerTest : IndexerBase, IInheritedIndexer
431+
{
431432
private System.Collections.Generic.IDictionary<int, string> d = new System.Collections.Generic.Dictionary<int, string>();
432433

433434
public string this[int index]
@@ -436,4 +437,13 @@ public string this[int index]
436437
set { t[index] = value; }
437438
}
438439
}
440+
441+
public class PublicInheritedOverloadedIndexer : PublicIndexerTest
442+
{
443+
public string this[string index]
444+
{
445+
get { return GetValue(index); }
446+
set { t[index] = value; }
447+
}
448+
}
439449
}

src/tests/test_indexer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,21 @@ def test_inherited_indexer_interface():
646646
ifc = IInheritedIndexer(impl)
647647
ifc[0] = "zero"
648648
assert ifc[0] == "zero"
649+
650+
def test_public_inherited_overloaded_indexer():
651+
"""Test public indexers."""
652+
ob = Test.PublicInheritedOverloadedIndexer()
653+
654+
ob[0] = "zero"
655+
assert ob[0] == "zero"
656+
657+
ob[1] = "one"
658+
assert ob[1] == "one"
659+
660+
assert ob[10] is None
661+
662+
ob["spam"] = "spam"
663+
assert ob["spam"] == "spam"
664+
665+
with pytest.raises(TypeError):
666+
ob[[]]

0 commit comments

Comments
 (0)