Skip to content

Commit

Permalink
Skip handling of void arrays for this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Nov 16, 2023
1 parent 19271ef commit 85a44ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/coreclr/classlibnative/bcltype/arraynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,10 +1826,6 @@ public static unsafe IEnumerable<object[]> CreateInstance_TestData()
new object[] { typeof(GenericInterface<int>), default(GenericInterface<int>) },
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 },
};
}

Expand Down Expand Up @@ -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<NotSupportedException>(() => Array.CreateInstanceFromArrayType(elementType.MakeArrayType(), 0));
Expand Down

0 comments on commit 85a44ff

Please sign in to comment.