Skip to content

Commit

Permalink
Fixed the binding of indexer overloads when there's more than one cla…
Browse files Browse the repository at this point in the history
…ss key.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Jun 13, 2017
1 parent c3f5b59 commit 37adb3e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Generator/Generators/CSharp/CSharpSources.cs
Expand Up @@ -2998,7 +2998,7 @@ public static string GetFunctionIdentifier(Function function)
identifier.Append(Helpers.GetSuffixFor(specialization));

var overloads = function.Namespace.GetOverloads(function)
.Where(f => f.IsGenerated).ToList();
.Where(f => f.IsGenerated || f.OperatorKind == CXXOperatorKind.Subscript).ToList();
var index = overloads.IndexOf(function);

if (index >= 0)
Expand Down
8 changes: 8 additions & 0 deletions tests/Common/Common.Tests.cs
Expand Up @@ -412,11 +412,19 @@ public void TestIndexers()
Assert.AreEqual(4, newProperties.Field);
newProperties.Field = 5;
Assert.AreEqual(5, indexedProperties[(byte) 0].Field);

var bar = new Bar { A = 5 };
indexedProperties[0u] = bar;
Assert.That(bar.A, Is.EqualTo(indexedProperties[0u].A));
indexedProperties[(ushort) 0] = bar;
Assert.That(bar.A, Is.EqualTo(indexedProperties[(ushort) 0].A));

using (var foo = new Foo())
{
var bar2 = new Bar { A = 10 };
indexedProperties[foo] = bar2;
Assert.That(bar2.A, Is.EqualTo(indexedProperties[foo].A));
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Common/Common.cpp
Expand Up @@ -449,6 +449,11 @@ TypeMappedIndex::TypeMappedIndex()
{
}

Bar& TestIndexedProperties::operator[](const Foo& key)
{
return bar;
}

InternalCtorAmbiguity::InternalCtorAmbiguity(void* param)
{
// cause a crash to indicate this is the incorrect ctor to invoke
Expand Down
1 change: 1 addition & 0 deletions tests/Common/Common.h
Expand Up @@ -568,6 +568,7 @@ class DLL_API TestIndexedProperties
foo_t operator[](TestProperties b);
Bar& operator[](unsigned long i);
Bar& operator[](const TypeMappedIndex& key);
Bar& operator[](const Foo& key);
// Test that we do not generate 'ref int' parameters as C# does not allow it
int operator[](CS_OUT char key);

Expand Down

0 comments on commit 37adb3e

Please sign in to comment.