From 4852c9c3100419e3976289655ede92b97ec2972e Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Thu, 19 Dec 2024 18:11:04 +0100 Subject: [PATCH] adds test for #640 --- HarmonyTests/Patching/Arguments.cs | 18 ++++++++++++++++++ HarmonyTests/Patching/Assets/ArgumentCases.cs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/HarmonyTests/Patching/Arguments.cs b/HarmonyTests/Patching/Arguments.cs index 587bb5d3..bb6130f2 100644 --- a/HarmonyTests/Patching/Arguments.cs +++ b/HarmonyTests/Patching/Arguments.cs @@ -396,5 +396,23 @@ public void Test_RenamedArguments() var log = RenamedArgumentsPatch.log.Join(); Assert.AreEqual("val1, patched, val2, hello", log); } + + [Test] + public void Test_NullableResults() + { + var res1 = new NullableResults().Method(); + Assert.True(res1.HasValue); + Assert.False(res1.Value); + + var harmony = new Harmony("test"); + var processor = new PatchClassProcessor(harmony, typeof(NullableResultsPatch)); + var patches = processor.Patch(); + Assert.NotNull(patches, "patches"); + Assert.AreEqual(1, patches.Count); + + var res2 = new NullableResults().Method(); + Assert.True(res2.HasValue); + Assert.True(res2.Value); + } } } diff --git a/HarmonyTests/Patching/Assets/ArgumentCases.cs b/HarmonyTests/Patching/Assets/ArgumentCases.cs index 06c32479..e7996e88 100644 --- a/HarmonyTests/Patching/Assets/ArgumentCases.cs +++ b/HarmonyTests/Patching/Assets/ArgumentCases.cs @@ -144,6 +144,24 @@ public static void Postfix([HarmonyArgument("__instance")] RenamedArguments foo2 } } + public class NullableResults + { + private string s = "foo"; + + [MethodImpl(MethodImplOptions.NoInlining)] + public bool? Method() => false; + } + + [HarmonyPatch(typeof(NullableResults), nameof(NullableResults.Method))] + public static class NullableResultsPatch + { + public static bool Prefix(ref bool? __result) + { + __result = true; + return false; + } + } + public class ArgumentArrayMethods { public struct SomeStruct