Skip to content

Commit 38e4bc3

Browse files
[RGen] Correctly cast enum results from the native invocation. (#23079)
1 parent 671268a commit 38e4bc3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ static partial class BindingSyntaxFactory {
108108
{ IsEnum: true, IsSmartEnum: true, IsNativeEnum: false }
109109
=> GetSmartEnumFromNSString (typeInfo.Delegate.ReturnType, Argument (auxIdentifier)),
110110

111+
// normal enum casting
112+
{ IsEnum: true, IsSmartEnum: false, IsNativeEnum: false }
113+
=> CastExpression (
114+
typeInfo.Delegate.ReturnType.GetIdentifierSyntax (),
115+
auxIdentifier.WithLeadingTrivia (Space)),
116+
111117
// string from native handle
112118
// CFString.FromHandle (auxVariable)!
113119
{ SpecialType: SpecialType.System_String, IsNullable: false}

tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedTrampolinePropertyTestsTrampolines.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public unsafe NIDAUInternalRenderBlock (global::ObjCRuntime.BlockLiteral *block)
563563
var ret = invoker (BlockLiteral, (global::AudioUnit.AudioUnitRenderActionFlags*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<global::AudioUnit.AudioUnitRenderActionFlags> (ref actionFlags), (global::AudioToolbox.AudioTimeStamp*) global::System.Runtime.CompilerServices.Unsafe.AsPointer<global::AudioToolbox.AudioTimeStamp> (ref timestamp), frameCount, outputBusNumber, outputData__handle__, realtimeEventListHead__handle__, NIDAUInternalRenderBlock.Create (pullInputBlock)!);
564564
global::System.GC.KeepAlive (outputData);
565565
global::System.GC.KeepAlive (realtimeEventListHead);
566-
return ret;
566+
return (global::AudioUnit.AudioUnitStatus) ret;
567567
}
568568
}
569569

tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryTrampolineTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,28 @@ public void MyMethod (Callback cb) {}
750750
"auxVariable"
751751
];
752752

753+
const string enumReturnType = @"
754+
using System;
755+
756+
namespace NS {
757+
758+
public enum TestEnum {
759+
First,
760+
Last
761+
}
762+
763+
public delegate TestEnum Callback()
764+
public class MyClass {
765+
public void MyMethod (Callback cb) {}
766+
}
767+
}
768+
";
769+
770+
yield return [
771+
enumReturnType,
772+
"(global::NS.TestEnum) auxVariable",
773+
];
774+
753775
const string voidReturnType = @"
754776
using System;
755777

0 commit comments

Comments
 (0)