diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-04-20 23:24:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 23:24:00 +0300 |
commit | e768b2e47c4d5f371bb30974463126d3b1751b5b (patch) | |
tree | 86cf78724aab0d03373beb3ae0abdc0f168eaffc /test/Mono.Linker.Tests.Cases | |
parent | fb5b3396eda1fb41765f04cad8b2cbd34d1fd53c (diff) |
Fix array dataflow tests (#2752)
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs index fb40089e4..0fb8cde8f 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs @@ -93,13 +93,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow arr[1].RequiresPublicMethods (); // Should warn - unknown value at this index } - [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), - ProducedBy = ProducedBy.Trimmer)] - [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), - ProducedBy = ProducedBy.Trimmer)] - // https://github.com/dotnet/linker/issues/2736 - [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll))] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll))] static void TestArraySetElementOneElementMix () { Type[] arr = new Type[1]; @@ -534,23 +529,46 @@ namespace Mono.Linker.Tests.Cases.DataFlow arr[0].RequiresAll (); } - [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), - ProducedBy = ProducedBy.Trimmer)] - // https://github.com/dotnet/linker/issues/2736 + [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll))] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll))] + static void TestNullCoalescingAssignment () + { + Type[] arr = new Type[1]; + arr[0] = GetTypeWithPublicConstructors (); + arr[0] ??= GetUnknownType (); + arr[0].RequiresAll (); + } + [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = ProducedBy.Analyzer)] - static void TestNullCoalescingAssignment () + // https://github.com/dotnet/linker/issues/2746 + [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), + ProducedBy = ProducedBy.Trimmer)] + static void TestNullCoalescingAssignmentToEmpty () { Type[] arr = new Type[1]; arr[0] ??= GetUnknownType (); arr[0].RequiresAll (); } - // Both linker and analyzer get this wrong. They should produce IL2072 instead. - // https://github.com/dotnet/linker/issues/2736 + [ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (DataFlowTypeExtensions.RequiresAll))] + // https://github.com/dotnet/linker/issues/2746 (Linker produces incomplete set of IL2072 warnings) + [ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), + ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), + ProducedBy = ProducedBy.Analyzer)] + static void TestNullCoalescingAssignmentComplex () + { + Type[] arr = new Type[1]; + arr[0] = GetWithPublicMethods (); + arr[0] ??= (GetUnknownType () ?? GetTypeWithPublicConstructors ()); + arr[0].RequiresAll (); + } + + // Linker only incidentally matches the analyzer behavior here. // https://github.com/dotnet/linker/issues/2737 [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))] - static void TestNullCoalescingAssignmentComplex () + static void TestNullCoalescingAssignmentToEmptyComplex () { Type[] arr = new Type[1]; arr[0] ??= (GetUnknownType () ?? GetTypeWithPublicConstructors ()); @@ -561,7 +579,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow { TestNullCoalesce (); TestNullCoalescingAssignment (); + TestNullCoalescingAssignmentToEmpty (); TestNullCoalescingAssignmentComplex (); + TestNullCoalescingAssignmentToEmptyComplex (); } } @@ -571,6 +591,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow return null; } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + private static Type GetWithPublicMethods () + { + return null; + } + private static Type GetUnknownType () { return null; |