Skip to content

Commit

Permalink
Fixed the generated C# for constant references to primitives.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Oct 13, 2018
1 parent 2fe8d21 commit 0c87a77
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Generator/Generators/CSharp/CSharpMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
if (Context.Function != null &&
Context.Function.OperatorKind == CXXOperatorKind.Subscript)
{
if (type.IsPrimitiveType(primitive) ||
new QualifiedType(pointer, quals).IsConstRefToPrimitive())
if (type.IsPrimitiveType(primitive))
{
Context.Return.Write("*");
}
Expand All @@ -199,6 +198,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
}
}

if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
Context.Return.Write("*");

Context.Return.Write(Context.ReturnVarName);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions tests/CSharp/CSharp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void TestUncompilableCode()
hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
}
Assert.That(foo.ReturnConstRef(), Is.EqualTo(5));
}
using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
hasOverride.CauseRenamingError();
Expand Down
5 changes: 5 additions & 0 deletions tests/CSharp/CSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ void Foo::set_width(int value)
{
}

const int& Foo::returnConstRef()
{
return rename;
}

const int Foo::rename;

int Foo::makeFunctionCall()
Expand Down
1 change: 1 addition & 0 deletions tests/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DLL_API Foo
void takesStdVector(const std::vector<int>& vector);
int width();
void set_width(int value);
const int& returnConstRef();

static const int rename = 5;
static int makeFunctionCall();
Expand Down

0 comments on commit 0c87a77

Please sign in to comment.