Skip to content

Commit a1327b4

Browse files
committed
Fixed the generated C# for indexers with dependent keys.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 0ea147b commit a1327b4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,12 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
556556
realPointer = templateSubstitution.Replacement.Type.Desugar() as PointerType;
557557
realPointer = realPointer ?? pointer;
558558
var pointee = pointer.Pointee.Desugar();
559-
if (Context.Function != null && realPointer.IsPrimitiveTypeConvertibleToRef() &&
560-
Context.MarshalKind != MarshalKind.VTableReturnValue &&
561-
Context.Function.OperatorKind != CXXOperatorKind.Subscript)
559+
if (Context.Function != null &&
560+
(realPointer.IsPrimitiveTypeConvertibleToRef() ||
561+
(templateSubstitution != null && realPointer.Pointee.IsEnumType())) &&
562+
Context.MarshalKind != MarshalKind.VTableReturnValue)
562563
{
563-
var refParamPtr = string.Format("__refParamPtr{0}", Context.ParameterIndex);
564+
var refParamPtr = $"__refParamPtr{Context.ParameterIndex}";
564565
if (templateSubstitution != null)
565566
{
566567
var castParam = $"__{Context.Parameter.Name}{Context.ParameterIndex}";
@@ -573,8 +574,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
573574
Context.Before.Write("&");
574575
Context.Before.WriteLine($"{castParam};");
575576
Context.Return.Write(refParamPtr);
577+
return true;
576578
}
577-
else
579+
if (Context.Function.OperatorKind != CXXOperatorKind.Subscript)
578580
{
579581
if (Context.Parameter.Kind == ParameterKind.PropertyValue)
580582
{
@@ -588,8 +590,8 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
588590
Context.Before.WriteStartBraceIndent();
589591
Context.Return.Write(refParamPtr);
590592
}
593+
return true;
591594
}
592-
return true;
593595
}
594596

595597
var param = Context.Parameter;

tests/CSharp/CSharpTemplates.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class TemplateWithIndexer
346346
public:
347347
TemplateWithIndexer();
348348
T& operator[](int i);
349+
T& operator[](const T& key);
349350
T& operator[](const char* string);
350351
private:
351352
T t[1];

0 commit comments

Comments
 (0)