Skip to content

Commit 3c55f7f

Browse files
committed
Worked around a bug in the Mono C# compiler when casting generics.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent a097cdd commit 3c55f7f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,16 @@ public override bool VisitClassDecl(Class @class)
304304
// if the class is an abstract impl, use the original for the object map
305305
var qualifiedClass = originalClass.Visit(typePrinter);
306306

307+
var finalType = (returnType.GetFinalPointee() ?? returnType).Desugar();
308+
Class returnedClass;
309+
if (finalType.TryGetClass(out returnedClass) && returnedClass.IsDependent)
310+
Context.Return.Write($"({returnType.Visit(typePrinter)}) (object) ");
311+
307312
if (returnType.IsAddress())
308313
Context.Return.Write(HandleReturnedPointer(@class, qualifiedClass.Type));
309314
else
310315
Context.Return.Write($"{qualifiedClass}.{Helpers.CreateInstanceIdentifier}({Context.ReturnVarName})");
311316

312-
var finalType = (returnType.GetFinalPointee() ?? returnType).Desugar();
313-
Class returnedClass;
314-
if (finalType.TryGetClass(out returnedClass) && returnedClass.IsDependent)
315-
Context.Return.Write($" as {returnType.Visit(typePrinter)}");
316317
return true;
317318
}
318319

0 commit comments

Comments
 (0)