diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs index 8f11a98281eee7..29b8bf650cbffa 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs @@ -65,6 +65,9 @@ public static void Main () GetUnderlyingTypeOnNonNullableKnownType.Test (); MakeGenericTypeWithUnknownValue (new object[2] { 1, 2 }); MakeGenericTypeWithKnowAndUnknownArray (); + + // Prevents optimizing away 'as Type' conversion. + PreserveSystemType (); } [Kept] @@ -331,5 +334,11 @@ static void MakeGenericTypeWithKnowAndUnknownArray (Type[] unknownTypes = null, nullable.GetProperties (); // This works - we still know it's Nullable<>, so we can get its properties Nullable.GetUnderlyingType (nullable).GetFields (); // This must warn - since we have no idea what the underlying type is for the unknownTypes case } + + [Kept] + static void PreserveSystemType () + { + typeof (Type).RequiresNonPublicConstructors (); + } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs index 68714608fcca98..4d2838c3b9ebfe 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs @@ -1,6 +1,7 @@ using System; using System.Reflection.Emit; using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Helpers; using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.UnreachableBlock @@ -14,6 +15,9 @@ public static void Main () { Test_1 (null); Test_2 (9); + + // Prevents optimizing away 'is Type' check. + PreserveSystemType (); } [Kept] @@ -100,5 +104,11 @@ static bool IsDynamicCodeSupported { static void Reached_1 () { } + + [Kept] + static void PreserveSystemType () + { + typeof (Type).RequiresNonPublicConstructors (); + } } } \ No newline at end of file