-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove ArrayClass::m_ElementType - get type from the type handle on M…
…ethodTable (#106787) `ArrayClass::m_ElementType` held a cached version of `MethodTable::m_ElementTypeHnd.GetSignatureCorElementType()`. This removes that member and makes `MethodTable::GetArrayElementType` (and therefore `ArrayBase::GetArrayElementType`) use the type handle to get the element type instead. This also fixes an issue where we were not always emitting a type check in array functions on arrays with elements that were object references. The added tests validate that these cases now result in an `ArrayTypeMismatchException` for mismatched element types.
- Loading branch information
1 parent
1b656fe
commit 8b34fb0
Showing
7 changed files
with
63 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
using Xunit; | ||
|
||
[ActiveIssue("https://github.com/dotnet/runtime/issues/107110", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsMonoInterpreter))] | ||
public class Arrays | ||
{ | ||
private class TestClass { } | ||
|
||
[Fact] | ||
public static void TypeMismatch_ArrayElement() | ||
{ | ||
Console.WriteLine($"Running {nameof(TypeMismatch_ArrayElement)}..."); | ||
TestClass[][] arr = new TestClass[1][]; | ||
MethodInfo arraySet = typeof(object[][]).GetMethod("Set"); | ||
Exception e = Assert.Throws<TargetInvocationException>(() => arraySet.Invoke(arr, [0, new object[] { new object() }])); | ||
Assert.IsType<ArrayTypeMismatchException>(e.InnerException); | ||
} | ||
|
||
[Fact] | ||
public static void TypeMismatch_MultidimensionalArrayElement() | ||
{ | ||
Console.WriteLine($"Running {nameof(TypeMismatch_MultidimensionalArrayElement)}..."); | ||
TestClass[][,] arr = new TestClass[1][,]; | ||
MethodInfo arraySet = typeof(object[][,]).GetMethod("Set"); | ||
Exception e = Assert.Throws<TargetInvocationException>(() => arraySet.Invoke(arr, [0, new object[1,1] { {new object()} }])); | ||
Assert.IsType<ArrayTypeMismatchException>(e.InnerException); | ||
} | ||
|
||
[Fact] | ||
public static void TypeMismatch_ClassElement() | ||
{ | ||
Console.WriteLine($"Running {nameof(TypeMismatch_ClassElement)}..."); | ||
{ | ||
TestClass[] arr = new TestClass[1]; | ||
MethodInfo arraySet = typeof(object[]).GetMethod("Set"); | ||
Exception e = Assert.Throws<TargetInvocationException>(() => arraySet.Invoke(arr, [0, new object()])); | ||
Assert.IsType<ArrayTypeMismatchException>(e.InnerException); | ||
} | ||
{ | ||
TestClass[,] arr = new TestClass[1,1]; | ||
MethodInfo arraySet = typeof(object[,]).GetMethod("Set"); | ||
Exception e = Assert.Throws<TargetInvocationException>(() => arraySet.Invoke(arr, [0, 0, new object()])); | ||
Assert.IsType<ArrayTypeMismatchException>(e.InnerException); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters