Skip to content

Commit

Permalink
Fixed the generated C# when an instance method has a parameter named …
Browse files Browse the repository at this point in the history
…"instance".

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Feb 14, 2019
1 parent b966bd6 commit 3164a89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/AST/FunctionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
@params.Add(new Parameter
{
QualifiedType = pointer,
Name = "instance",
Name = "__instance",
Namespace = function
});
}
Expand All @@ -32,7 +32,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
@params.Add(new Parameter
{
QualifiedType = pointer,
Name = "instance",
Name = "__instance",
Namespace = function
});
}
Expand All @@ -57,7 +57,7 @@ public static IList<Parameter> GatherInternalParams(this Function function,
@params.Add(new Parameter
{
QualifiedType = pointer,
Name = "instance",
Name = "__instance",
Namespace = function
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/Generator/Generators/CSharp/CSharpSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1786,12 +1786,13 @@ private void GenerateVTableMethodDelegates(Class @class, Method method)
string.Join(", ", @params));
WriteOpenBraceAndIndent();

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

var printedClass = @class.Visit(TypePrinter);
WriteLine($"var {Helpers.TargetIdentifier} = ({printedClass}) NativeToManagedMap[instance];");
WriteLine($@"var {Helpers.TargetIdentifier} = ({
printedClass}) NativeToManagedMap[{Helpers.InstanceField}];");
WriteLine("if ({0}.{1})", Helpers.TargetIdentifier, Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
GenerateVTableManagedCall(method);
Expand Down
10 changes: 9 additions & 1 deletion tests/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ HasOverloadsWithDifferentPointerKindsToSameType::~HasOverloadsWithDifferentPoint
{
}

void HasOverloadsWithDifferentPointerKindsToSameType::overload(int& in)
void HasOverloadsWithDifferentPointerKindsToSameType::overload(int& i)
{
}

Expand Down Expand Up @@ -991,6 +991,14 @@ void DerivedFromSecondaryBaseWithIgnoredVirtualMethod::ignored(const IgnoredType
{
}

AmbiguousParamNames::AmbiguousParamNames(int instance, int in)
{
}

AmbiguousParamNames::~AmbiguousParamNames()
{
}

void integerOverload(int i)
{
}
Expand Down
11 changes: 9 additions & 2 deletions tests/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ class DLL_API HasOverloadsWithDifferentPointerKindsToSameType
public:
HasOverloadsWithDifferentPointerKindsToSameType();
~HasOverloadsWithDifferentPointerKindsToSameType();
void overload(int& in);
void overload(int& i);
void overload(int&& i);
void overload(const int& i);
void overload(const Foo& rx, int from = -1);
Expand Down Expand Up @@ -1394,6 +1394,13 @@ class DLL_API DerivedFromSecondaryBaseWithIgnoredVirtualMethod : public Foo, pub
void ignored(const IgnoredType& ignoredParam);
};

class DLL_API AmbiguousParamNames
{
public:
AmbiguousParamNames(int instance, int in);
~AmbiguousParamNames();
};

template<typename T> void TemplatedFunction(T type)
{

Expand All @@ -1403,7 +1410,7 @@ inline namespace InlineNamespace
{
void FunctionInsideInlineNamespace()
{

}
}

Expand Down

0 comments on commit 3164a89

Please sign in to comment.