From f9118745364592153a68b69a5848b5166ae1aef4 Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Thu, 23 Nov 2023 17:46:09 +0100 Subject: [PATCH] Fix explictly setting the return type on a dynamic method --- .../tests/MethodBuilder/MethodBuilderSetReturnType.cs | 1 - .../src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetReturnType.cs b/src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetReturnType.cs index 6245fbb2dccf2..7fe59ee9b09da 100644 --- a/src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetReturnType.cs +++ b/src/libraries/System.Reflection.Emit/tests/MethodBuilder/MethodBuilderSetReturnType.cs @@ -132,7 +132,6 @@ public void SetReturnType_TypeCreated_Works() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)] public void SetReturnType_NullReturnType_ReturnsVoid() { TypeBuilder type = Helpers.DynamicType(TypeAttributes.Abstract); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs index 8e4503ce9934f..4083d7378ac1a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs @@ -603,7 +603,9 @@ protected override void SetSignatureCore(Type? returnType, Type[]? returnTypeReq Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); } - rtype = returnType; + if (returnType != null) + rtype = returnType; + returnModReq = returnTypeRequiredCustomModifiers; returnModOpt = returnTypeOptionalCustomModifiers; paramModReq = parameterTypeRequiredCustomModifiers;