Skip to content

Commit

Permalink
Add negative test for creating instances of function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed May 3, 2023
1 parent 372b01f commit 5ad8b44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/libraries/System.Runtime/tests/System/ActivatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ public static IEnumerable<object[]> 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*<int, int>);
}
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ private static void FillStack(int depth)

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
Expand All @@ -227,11 +225,18 @@ public static IEnumerable<object[]> 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*<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)
Expand Down

0 comments on commit 5ad8b44

Please sign in to comment.