diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs | 1 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs | 82 |
2 files changed, 83 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs index d19a1fb82..90c24fd9f 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs @@ -11,6 +11,7 @@ using DAMT = System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes; namespace Mono.Linker.Tests.Cases.DataFlow { [ExpectedNoWarnings] + [KeptPrivateImplementationDetails ("ThrowSwitchExpressionException")] class NullableAnnotations { [Kept] diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs index 2128b8e41..15508baca 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs @@ -45,6 +45,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow BasePropertyAccess.Test (); AccessReturnedInstanceProperty.Test (); + + ExplicitIndexerAccess.Test (); + ImplicitIndexerAccess.Test (); } [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] @@ -653,6 +656,85 @@ namespace Mono.Linker.Tests.Cases.DataFlow } } + class ExplicitIndexerAccess + { + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + Type this[Index idx] { + get => throw new NotImplementedException (); + set => throw new NotImplementedException (); + } + + [ExpectedWarning ("IL2072", "this[Index].get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = ProducedBy.Trimmer)] + static void TestRead (ExplicitIndexerAccess instance = null) + { + instance[new Index (1)].RequiresAll (); + } + + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "this[Index].set", ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = ProducedBy.Trimmer)] + static void TestWrite (ExplicitIndexerAccess instance = null) + { + instance[^1] = GetTypeWithPublicConstructors (); + } + + public static void Test () + { + TestRead (); + TestWrite (); + } + } + + class ImplicitIndexerAccess + { + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + Type this[int idx] { + get => throw new NotImplementedException (); + set => throw new NotImplementedException (); + } + + int Length => throw new NotImplementedException (); + + [ExpectedWarning ("IL2072", "this[Int32].get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = ProducedBy.Trimmer)] + static void TestRead (ImplicitIndexerAccess instance = null) + { + instance[new Index (1)].RequiresAll (); + } + + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "this[Int32].set", ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = ProducedBy.Trimmer)] + static void TestWrite (ImplicitIndexerAccess instance = null) + { + instance[^1] = GetTypeWithPublicConstructors (); + } + + [ExpectedWarning ("IL2072", nameof (GetUnknownType), "this[Int32].set", ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (GetUnknownType), "Item.set", ProducedBy = ProducedBy.Trimmer)] + static void TestNullCoalescingAssignment (ImplicitIndexerAccess instance = null) + { + instance[new Index (1)] ??= GetUnknownType (); + } + + [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))] + static void TestSpanIndexerAccess (int start = 0, int end = 3) + { + Span<byte> bytes = stackalloc byte[4] { 1, 2, 3, 4 }; + bytes[^4] = 0; // This calls the get indexer which has a ref return. + int index = bytes[0]; + Type[] types = new Type[] { GetUnknownType () }; + types[index].RequiresAll (); + } + + public static void Test () + { + TestRead (); + TestWrite (); + TestNullCoalescingAssignment (); + TestSpanIndexerAccess (); + } + } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] private static Type GetTypeWithPublicParameterlessConstructor () { |