Add negative test for creating instances of function pointers (#85709)
authorJan Kotas <jkotas@microsoft.com>
Thu, 4 May 2023 12:22:02 +0000 (05:22 -0700)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 12:22:02 +0000 (05:22 -0700)
src/libraries/System.Runtime/tests/System/ActivatorTests.cs
src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs

index 3833e79..b65b9b4 100644 (file)
@@ -198,6 +198,13 @@ namespace System.Tests
             yield return new object[] { typeof(int[]) };
             yield return new object[] { typeof(int).MakeByRefType() };
             yield return new object[] { typeof(int).MakePointerType() };
+
+            // https://github.com/dotnet/runtime/issues/71095
+            if (!PlatformDetection.IsMonoRuntime)
+            {
+                yield return new object[] { FunctionPointerType() };
+                static unsafe Type FunctionPointerType() => typeof(delegate*<int, int>);
+            }
         }
 
         [Theory]
index 12112f8..5568a5f 100644 (file)
@@ -203,8 +203,6 @@ namespace System.Runtime.CompilerServices.Tests
 
         public static IEnumerable<object[]> GetUninitializedObject_NegativeTestCases()
         {
-            // TODO: Test actual function pointer types when typeof(delegate*<...>) support is available
-
             yield return new[] { typeof(string), typeof(ArgumentException) }; // variable-length type
             yield return new[] { typeof(int[]), typeof(ArgumentException) }; // variable-length type
             yield return new[] { typeof(int[,]), typeof(ArgumentException) }; // variable-length type
@@ -227,11 +225,18 @@ namespace System.Runtime.CompilerServices.Tests
             yield return new[] { typeof(Delegate), typeof(MemberAccessException) }; // abstract type
 
             yield return new[] { typeof(void), typeof(ArgumentException) }; // explicit block in place
-            yield return new[] { typeof(int).MakePointerType(), typeof(ArgumentException) }; // pointer typedesc
-            yield return new[] { typeof(int).MakeByRefType(), typeof(ArgumentException) }; // byref typedesc
+            yield return new[] { typeof(int).MakePointerType(), typeof(ArgumentException) }; // pointer
+            yield return new[] { typeof(int).MakeByRefType(), typeof(ArgumentException) }; // byref
+
+            // https://github.com/dotnet/runtime/issues/71095
+            if (!PlatformDetection.IsMonoRuntime)
+            {
+                yield return new[] { FunctionPointerType(), typeof(ArgumentException) }; // function pointer
+                static unsafe Type FunctionPointerType() => typeof(delegate*<void>);
+            }
 
-            yield return new[] { typeof(ReadOnlySpan<int>), typeof(NotSupportedException) }; // byref type
-            yield return new[] { typeof(ArgIterator), typeof(NotSupportedException) }; // byref type
+            yield return new[] { typeof(ReadOnlySpan<int>), typeof(NotSupportedException) }; // byref-like type
+            yield return new[] { typeof(ArgIterator), typeof(NotSupportedException) }; // byref-like type
 
             Type canonType = typeof(object).Assembly.GetType("System.__Canon", throwOnError: false);
             if (canonType != null)