diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-05-03 20:58:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 20:58:17 +0300 |
commit | 6e5d7af73d7ff6a959a9be391d2731c8f7448b95 (patch) | |
tree | 14b07e4ecf3f83d5f8b401dfc018acff30ba0745 /test | |
parent | 05a3b652d525acaac1307221b62db979d0108692 (diff) |
Adds support for recognizing more integer types as consts (#2781)
Added a test based on array analysis which uses integers as indeces to the array.
Diffstat (limited to 'test')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs index 0fb8cde8f..7331f81ac 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs @@ -43,6 +43,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow TestMultiDimensionalArray.Test (); WriteCapturedArrayElement.Test (); + + ConstantFieldValuesAsIndex.Test (); } [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicMethods))] @@ -585,6 +587,32 @@ namespace Mono.Linker.Tests.Cases.DataFlow } } + class ConstantFieldValuesAsIndex + { + private const sbyte ConstSByte = 1; + private const byte ConstByte = 1; + private const short ConstShort = 1; + private const ushort ConstUShort = 1; + private const int ConstInt = 1; + private const uint ConstUInt = 1; + // Longs and ULongs would need support for conversion logic, which is not implement yet + + public static void Test () + { + var types = new Type[2]; + types[0] = GetUnknownType (); + types[1] = typeof (TestType); + + // All the consts are 1, so there should be no warnings + types[ConstSByte].RequiresPublicMethods (); + types[ConstByte].RequiresPublicMethods (); + types[ConstShort].RequiresPublicMethods (); + types[ConstUShort].RequiresPublicMethods (); + types[ConstInt].RequiresPublicMethods (); + types[ConstUInt].RequiresPublicMethods (); + } + } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetTypeWithPublicConstructors () { |