Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negative test for creating instances of function pointers #85709

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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