From e4b860c053745004a08b6499c58de210cd078c47 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 9 Feb 2014 18:12:24 +0200 Subject: [PATCH] Fixed wrong code generated for indexers in value types. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 5 ++++- tests/Basic/Basic.cpp | 2 +- tests/Basic/Basic.h | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index fb4c598f..0b946a06 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2283,7 +2283,10 @@ namespace CppSharp.Generators.CSharp if (needsFixedThis) { WriteLine("var {0} = {1};", Generator.GeneratedIdentifier("fixedInstance"), - method.IsOperator ? "__arg0" : "ToInternal()"); + (method.IsOperator && method.OperatorKind != CXXOperatorKind.Subscript ? + method.Parameters.First( + p => p.Kind == ParameterKind.OperatorParameter).Name + "." : + string.Empty) + "ToInternal()"); } if (needsReturn && !originalFunction.HasIndirectReturnTypeParameter) diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 54b709e9..73859d4e 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -251,5 +251,5 @@ int test(basic& s) Bar::Item operator |(Bar::Item left, Bar::Item right) { - return left; + return left | right; } diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 3e121523..36654fa4 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -433,6 +433,14 @@ const foo_t& TestIndexedProperties::operator[](double f) { return p; } TestProperties* TestIndexedProperties::operator[](unsigned char b) { return &f; } const TestProperties& TestIndexedProperties::operator[](short b) { return f; } +struct DLL_API TestIndexedPropertiesInValueType +{ +public: + int operator[](int i); +}; + +int TestIndexedPropertiesInValueType::operator[](int i) { return i; } + enum struct MyEnum { A, B, C }; class DLL_API TestArraysPointers