Skip to content

Commit e430f6f

Browse files
committed
Fix regressed indexers in templates with non-trivial ctors
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent fac861a commit e430f6f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ private void MarshalRefClass(Class @class)
711711
Context.Parameter.Name}"", ""Cannot be null because it is passed by value."");");
712712
var realClass = @class.OriginalClass ?? @class;
713713
var qualifiedIdentifier = typePrinter.PrintNative(realClass);
714-
Context.Return.Write($"*({qualifiedIdentifier}*) {paramInstance}");
714+
Context.ArgumentPrefix.Write($"*({qualifiedIdentifier}*) ");
715+
Context.Return.Write(paramInstance);
715716
return;
716717
}
717718

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,8 @@ private void GenerateVariableSetter(Variable var)
876876
if (ctx.HasCodeBlock)
877877
Indent();
878878

879-
WriteLine($"*{ptr} = {marshal.Context.Return};", marshal.Context.Return);
879+
WriteLine($@"*{ptr} = {marshal.Context.ArgumentPrefix}{
880+
marshal.Context.Return};", marshal.Context.Return);
880881

881882
if (ctx.HasCodeBlock)
882883
UnindentAndWriteCloseBrace();
@@ -974,7 +975,7 @@ private void GenerateFieldSetter(Field field, Class @class, QualifiedType fieldT
974975
Write("(object) ");
975976
}
976977
}
977-
WriteLine($"{marshal.Context.Return};");
978+
WriteLine($"{marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
978979
}
979980

980981
if ((arrayType != null && @class.IsValueType) || ctx.HasCodeBlock)
@@ -1049,21 +1050,21 @@ private void GenerateIndexerSetter(Function function)
10491050
GetInstanceParam(function)}, {paramMarshal.Context.ArgumentPrefix}{paramMarshal.Name})";
10501051
if (type.IsPrimitiveType())
10511052
{
1052-
WriteLine($"*{call} = {marshal.Context.Return};");
1053+
WriteLine($"*{call} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
10531054
}
10541055
else
10551056
{
10561057
Class @class;
10571058
if (type.TryGetClass(out @class) && @class.HasNonTrivialCopyConstructor)
10581059
{
10591060
Method cctor = @class.Methods.First(c => c.IsCopyConstructor);
1060-
WriteLine($@"{@class.Visit(TypePrinter)}.{Helpers.InternalStruct}.{
1061-
GetFunctionNativeIdentifier(cctor)}({call}, {
1062-
ctx.Parameter.Name}.{Helpers.InstanceIdentifier});");
1061+
WriteLine($@"{TypePrinter.PrintNative(type)}.{
1062+
GetFunctionNativeIdentifier(cctor)}({call}, {marshal.Context.Return});");
10631063
}
10641064
else
10651065
{
1066-
WriteLine($"*({TypePrinter.PrintNative(type)}*) {call} = {marshal.Context.Return};");
1066+
WriteLine($@"*({TypePrinter.PrintNative(type)}*) {call} = {
1067+
marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
10671068
}
10681069
}
10691070
}
@@ -1790,13 +1791,12 @@ private void GenerateVTableManagedCall(Method method)
17901791
if (method.HasIndirectReturnTypeParameter)
17911792
{
17921793
var retParam = method.Parameters.First(p => p.Kind == ParameterKind.IndirectReturnType);
1793-
WriteLine("*({0}*) {1} = {2};",
1794-
TypePrinter.PrintNative(method.OriginalReturnType),
1795-
retParam.Name, marshal.Context.Return);
1794+
WriteLine($@"*({TypePrinter.PrintNative(method.OriginalReturnType)}*) {
1795+
retParam.Name} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
17961796
}
17971797
else
17981798
{
1799-
WriteLine("return {0};", marshal.Context.Return);
1799+
WriteLine($"return {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
18001800
}
18011801
}
18021802

0 commit comments

Comments
 (0)