Skip to content

Commit 5ad8b44

Browse files
committed
Add negative test for creating instances of function pointers
1 parent 372b01f commit 5ad8b44

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/libraries/System.Runtime/tests/System/ActivatorTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ public static IEnumerable<object[]> CreateInstance_NoDefaultConstructor_TestData
198198
yield return new object[] { typeof(int[]) };
199199
yield return new object[] { typeof(int).MakeByRefType() };
200200
yield return new object[] { typeof(int).MakePointerType() };
201+
202+
// https://github.com/dotnet/runtime/issues/71095
203+
if (!PlatformDetection.IsMonoRuntime)
204+
{
205+
yield return new object[] { FunctionPointerType() };
206+
static unsafe Type FunctionPointerType() => typeof(delegate*<int, int>);
207+
}
201208
}
202209

203210
[Theory]

src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ private static void FillStack(int depth)
203203

204204
public static IEnumerable<object[]> GetUninitializedObject_NegativeTestCases()
205205
{
206-
// TODO: Test actual function pointer types when typeof(delegate*<...>) support is available
207-
208206
yield return new[] { typeof(string), typeof(ArgumentException) }; // variable-length type
209207
yield return new[] { typeof(int[]), typeof(ArgumentException) }; // variable-length type
210208
yield return new[] { typeof(int[,]), typeof(ArgumentException) }; // variable-length type
@@ -227,11 +225,18 @@ public static IEnumerable<object[]> GetUninitializedObject_NegativeTestCases()
227225
yield return new[] { typeof(Delegate), typeof(MemberAccessException) }; // abstract type
228226

229227
yield return new[] { typeof(void), typeof(ArgumentException) }; // explicit block in place
230-
yield return new[] { typeof(int).MakePointerType(), typeof(ArgumentException) }; // pointer typedesc
231-
yield return new[] { typeof(int).MakeByRefType(), typeof(ArgumentException) }; // byref typedesc
228+
yield return new[] { typeof(int).MakePointerType(), typeof(ArgumentException) }; // pointer
229+
yield return new[] { typeof(int).MakeByRefType(), typeof(ArgumentException) }; // byref
230+
231+
// https://github.com/dotnet/runtime/issues/71095
232+
if (!PlatformDetection.IsMonoRuntime)
233+
{
234+
yield return new[] { FunctionPointerType(), typeof(ArgumentException) }; // function pointer
235+
static unsafe Type FunctionPointerType() => typeof(delegate*<void>);
236+
}
232237

233-
yield return new[] { typeof(ReadOnlySpan<int>), typeof(NotSupportedException) }; // byref type
234-
yield return new[] { typeof(ArgIterator), typeof(NotSupportedException) }; // byref type
238+
yield return new[] { typeof(ReadOnlySpan<int>), typeof(NotSupportedException) }; // byref-like type
239+
yield return new[] { typeof(ArgIterator), typeof(NotSupportedException) }; // byref-like type
235240

236241
Type canonType = typeof(object).Assembly.GetType("System.__Canon", throwOnError: false);
237242
if (canonType != null)

0 commit comments

Comments
 (0)