From 85a44ff1d4c5e66ff649e2a8566746a93ec6aca0 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 15 Nov 2023 23:57:40 -0800 Subject: [PATCH] Skip handling of void arrays for this PR --- .../classlibnative/bcltype/arraynative.cpp | 5 +++-- .../src/System/Array.NativeAot.cs | 20 ++++++++----------- .../System.Runtime.Tests/System/ArrayTests.cs | 7 ------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/coreclr/classlibnative/bcltype/arraynative.cpp b/src/coreclr/classlibnative/bcltype/arraynative.cpp index 4d12f892987b9..0c1afdcbfd8b7 100644 --- a/src/coreclr/classlibnative/bcltype/arraynative.cpp +++ b/src/coreclr/classlibnative/bcltype/arraynative.cpp @@ -732,7 +732,7 @@ static void CheckElementType(TypeHandle elementType) COMPlusThrow(kNotSupportedException, W("NotSupported_ByRefLikeArray")); // Check for open generic types. - if (pMT->IsGenericTypeDefinition() || pMT->ContainsGenericVariables()) + if (pMT->ContainsGenericVariables()) COMPlusThrow(kNotSupportedException, W("NotSupported_OpenType")); // Check for Void. @@ -765,7 +765,8 @@ void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT3 _ASSERTE((INT32)typeHnd.GetRank() == rank); _ASSERTE(typeHnd.IsArray()); - CheckElementType(typeHnd.GetArrayElementTypeHandle()); + if (typeHnd.GetArrayElementTypeHandle().ContainsGenericVariables()) + COMPlusThrow(kNotSupportedException, W("NotSupported_OpenType")); if (!typeHnd.AsMethodTable()->IsMultiDimArray()) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.NativeAot.cs index cf138900f4a1b..fa2db3712e060 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.NativeAot.cs @@ -58,7 +58,12 @@ internal unsafe bool IsSzArray [RequiresDynamicCode("The code for an array of the specified type might not be available.")] private static unsafe Array InternalCreate(RuntimeType elementType, int rank, int* pLengths, int* pLowerBounds) { - ValidateElementType(elementType); + if (elementType.IsByRef || elementType.IsByRefLike) + throw new NotSupportedException(SR.NotSupported_ByRefLikeArray); + if (elementType == typeof(void)) + throw new NotSupportedException(SR.NotSupported_VoidArray); + if (elementType.ContainsGenericParameters) + throw new NotSupportedException(SR.NotSupported_OpenType); if (pLowerBounds != null) { @@ -93,7 +98,8 @@ private static unsafe Array InternalCreateFromArrayType(RuntimeType arrayType, i Debug.Assert(arrayType.IsArray); Debug.Assert(arrayType.GetArrayRank() == rank); - ValidateElementType(arrayType.GetElementType()); + if (arrayType.ContainsGenericParameters) + throw new NotSupportedException(SR.NotSupported_OpenType); if (pLowerBounds != null) { @@ -125,16 +131,6 @@ private static unsafe Array InternalCreateFromArrayType(RuntimeType arrayType, i } } - private static void ValidateElementType(Type elementType) - { - if (elementType.IsByRef || elementType.IsByRefLike) - throw new NotSupportedException(SR.NotSupported_ByRefLikeArray); - if (elementType == typeof(void)) - throw new NotSupportedException(SR.NotSupported_VoidArray); - if (elementType.ContainsGenericParameters) - throw new NotSupportedException(SR.NotSupported_OpenType); - } - public unsafe void Initialize() { EETypePtr pElementEEType = ElementEEType; diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArrayTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArrayTests.cs index 1546fad4f40c1..e2ba16c2e8069 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArrayTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArrayTests.cs @@ -1826,10 +1826,6 @@ public static unsafe IEnumerable CreateInstance_TestData() new object[] { typeof(GenericInterface), default(GenericInterface) }, new object[] { typeof(AbstractClass), default(AbstractClass) }, new object[] { typeof(StaticClass), default(StaticClass) }, - - // Arrays of void arrays - new object[] { typeof(void).MakeArrayType(), null }, - new object[] { typeof(void).MakeArrayType(1), null }, }; } @@ -1950,10 +1946,7 @@ public void CreateInstance_NotSupportedType_ThrowsNotSupportedException(Type ele } [Theory] - [InlineData(typeof(void))] [InlineData(typeof(GenericClass<>))] - // not using any by-ref type here as MakeArrayType throws for them, same goes for Type.GetType("SomeByRef[]") - [ActiveIssue("https://github.com/dotnet/runtime/issues/94086", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime))] public void CreateInstanceFromArrayType_NotSupportedArrayType_ThrowsNotSupportedException(Type elementType) { Assert.Throws(() => Array.CreateInstanceFromArrayType(elementType.MakeArrayType(), 0));