Skip to content

Commit bc7f20a

Browse files
committed
Fixed the generated C# when an instance method has a parameter named "instance".
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent b966bd6 commit bc7f20a

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

src/AST/FunctionExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
2121
@params.Add(new Parameter
2222
{
2323
QualifiedType = pointer,
24-
Name = "instance",
24+
Name = "__instance",
2525
Namespace = function
2626
});
2727
}
@@ -32,7 +32,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
3232
@params.Add(new Parameter
3333
{
3434
QualifiedType = pointer,
35-
Name = "instance",
35+
Name = "__instance",
3636
Namespace = function
3737
});
3838
}
@@ -57,7 +57,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
5757
@params.Add(new Parameter
5858
{
5959
QualifiedType = pointer,
60-
Name = "instance",
60+
Name = "__instance",
6161
Namespace = function
6262
});
6363
}

src/Generator/Generators/CSharp/CSharpSources.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1786,12 +1786,13 @@ private void GenerateVTableMethodDelegates(Class @class, Method method)
17861786
string.Join(", ", @params));
17871787
WriteOpenBraceAndIndent();
17881788

1789-
WriteLine("if (!NativeToManagedMap.ContainsKey(instance))");
1789+
WriteLine($"if (!NativeToManagedMap.ContainsKey({Helpers.InstanceField}))");
17901790
WriteLineIndent("throw new global::System.Exception(\"No managed instance was found\");");
17911791
NewLine();
17921792

17931793
var printedClass = @class.Visit(TypePrinter);
1794-
WriteLine($"var {Helpers.TargetIdentifier} = ({printedClass}) NativeToManagedMap[instance];");
1794+
WriteLine($@"var {Helpers.TargetIdentifier} = ({
1795+
printedClass}) NativeToManagedMap[{Helpers.InstanceField}];");
17951796
WriteLine("if ({0}.{1})", Helpers.TargetIdentifier, Helpers.OwnsNativeInstanceIdentifier);
17961797
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
17971798
GenerateVTableManagedCall(method);

tests/Common/Common.Tests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public unsafe void TestCodeGeneration()
5555
ItemsDifferByCase itemsDifferByCase = ItemsDifferByCase.Case_a;
5656
itemsDifferByCase = ItemsDifferByCase.CaseA;
5757
itemsDifferByCase.GetHashCode();
58+
new AmbiguousParamNames(0, 0).Dispose();
5859
Common.SMallFollowedByCapital();
5960
Common.IntegerOverload(0);
6061
Common.IntegerOverload((uint) 0);

tests/Common/Common.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ HasOverloadsWithDifferentPointerKindsToSameType::~HasOverloadsWithDifferentPoint
848848
{
849849
}
850850

851-
void HasOverloadsWithDifferentPointerKindsToSameType::overload(int& in)
851+
void HasOverloadsWithDifferentPointerKindsToSameType::overload(int& i)
852852
{
853853
}
854854

@@ -991,6 +991,14 @@ void DerivedFromSecondaryBaseWithIgnoredVirtualMethod::ignored(const IgnoredType
991991
{
992992
}
993993

994+
AmbiguousParamNames::AmbiguousParamNames(int instance, int in)
995+
{
996+
}
997+
998+
AmbiguousParamNames::~AmbiguousParamNames()
999+
{
1000+
}
1001+
9941002
void integerOverload(int i)
9951003
{
9961004
}

tests/Common/Common.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ class DLL_API HasOverloadsWithDifferentPointerKindsToSameType
13101310
public:
13111311
HasOverloadsWithDifferentPointerKindsToSameType();
13121312
~HasOverloadsWithDifferentPointerKindsToSameType();
1313-
void overload(int& in);
1313+
void overload(int& i);
13141314
void overload(int&& i);
13151315
void overload(const int& i);
13161316
void overload(const Foo& rx, int from = -1);
@@ -1394,6 +1394,13 @@ class DLL_API DerivedFromSecondaryBaseWithIgnoredVirtualMethod : public Foo, pub
13941394
void ignored(const IgnoredType& ignoredParam);
13951395
};
13961396

1397+
class DLL_API AmbiguousParamNames
1398+
{
1399+
public:
1400+
AmbiguousParamNames(int instance, int in);
1401+
~AmbiguousParamNames();
1402+
};
1403+
13971404
template<typename T> void TemplatedFunction(T type)
13981405
{
13991406

@@ -1403,7 +1410,7 @@ inline namespace InlineNamespace
14031410
{
14041411
void FunctionInsideInlineNamespace()
14051412
{
1406-
1413+
14071414
}
14081415
}
14091416

0 commit comments

Comments
 (0)