From 5ad8b448b5f0b9a8faddac7c74fafdfe21b6937f Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 3 May 2023 06:58:03 -0700 Subject: [PATCH] Add negative test for creating instances of function pointers --- .../tests/System/ActivatorTests.cs | 7 +++++++ .../CompilerServices/RuntimeHelpersTests.cs | 17 +++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/ActivatorTests.cs b/src/libraries/System.Runtime/tests/System/ActivatorTests.cs index 3833e79305f25c..b65b9b43ec624e 100644 --- a/src/libraries/System.Runtime/tests/System/ActivatorTests.cs +++ b/src/libraries/System.Runtime/tests/System/ActivatorTests.cs @@ -198,6 +198,13 @@ public static IEnumerable CreateInstance_NoDefaultConstructor_TestData 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*); + } } [Theory] diff --git a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs index 12112f88e7718d..5568a5f62eb177 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs @@ -203,8 +203,6 @@ private static void FillStack(int depth) public static IEnumerable 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 @@ public static IEnumerable GetUninitializedObject_NegativeTestCases() 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*); + } - yield return new[] { typeof(ReadOnlySpan), typeof(NotSupportedException) }; // byref type - yield return new[] { typeof(ArgIterator), typeof(NotSupportedException) }; // byref type + yield return new[] { typeof(ReadOnlySpan), 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)