Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TypeHierarchySuppressions.cs « Reflection « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 419fa4723d00dbf55f7a6028003f9ff390aa6508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// 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.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Reflection
{
	[ExpectedNoWarnings]
	public class TypeHierarchySuppressions
	{
		public static void Main ()
		{
			RequireMethods (unsuppressed.GetType ());
			RequireMethods (suppressed.GetType ());
			RequireAll (annotatedAllSuppressed.GetType ());

			var t = typeof (DerivedFromSuppressed1);
			var t2 = typeof (DerivedFromUnsuppressed1);
			var t3 = typeof (SuppressedOnDerived1);
			var t4 = typeof (SuppressedBaseWarningsOnDerived);

			UseDerivedTypes ();

			// Suppressing type hierarchy warnings is unsafe because it allows
			// derived types to access annotated methods without any warnings:
			derivedFromSuppressed.GetType ().GetMethod ("RUCDerivedMethod");

		}

		[Kept]
		static void UseDerivedTypes ()
		{
			var t = typeof (DerivedFromUnsuppressed2);
			var t2 = typeof (DerivedFromSuppressed2);
			var t3 = typeof (SuppressedOnDerived2);
		}

		[Kept]
		static Unsuppressed unsuppressed;
		[Kept]
		static Suppressed suppressed;
		[Kept]
		static DerivedFromSuppressed1 derivedFromSuppressed;
		[Kept]
		static AnnotatedAllSuppressed annotatedAllSuppressed;

		[Kept]
		static void RequireMethods (
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
			Type type)
		{ }

		[Kept]
		static void RequireAll (
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
			Type type)
		{ }

		[Kept]
		[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
		[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
		class Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on Unsuppressed--")]
			[RequiresUnreferencedCode ("--RUC on Unsuppressed--")]
			public void RUCMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Unsuppressed))]
		class DerivedFromUnsuppressed1 : Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on DerivedFromUnsuppressed1--")]
			[RequiresUnreferencedCode ("--RUC on DerivedFromUnsuppressed1--")]
			public void DerivedRUCMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Unsuppressed))]
		class DerivedFromUnsuppressed2 : Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on DerivedFromUnsuppressed2")]
			[RequiresUnreferencedCode ("--RUC on DerivedFromUnsuppressed2--")]
			public void DerivedRUCMethod () { }
		}

		[Kept]
		[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
		[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
		[UnconditionalSuppressMessage ("TrimAnalysis", "IL2112")]
		[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
		class Suppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[RequiresUnreferencedCode ("--RUC on Suppressed--")]
			public void RUCMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Suppressed))]
		class DerivedFromSuppressed1 : Suppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on DerivedFromSuppressed1--")]
			[RequiresUnreferencedCode ("--RUC on DerivedFromSuppressed1--")]
			public void RUCDerivedMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Suppressed))]
		class DerivedFromSuppressed2 : Suppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on DerivedFromSuppressed2--")]
			[RequiresUnreferencedCode ("--RUC on DerivedFromSuppressed2--")]
			public void RUCDerivedMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Unsuppressed))]
		class SuppressedOnDerived1 : Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
			[UnconditionalSuppressMessage ("TrimAnalysis", "IL2112")]
			[RequiresUnreferencedCode ("--RUC on SuppressedOnDerived1--")]
			public void DerivedRUCMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Unsuppressed))]
		class SuppressedOnDerived2 : Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
			[UnconditionalSuppressMessage ("TrimAnalysis", "IL2112")]
			[RequiresUnreferencedCode ("--RUC on SuppressedOnDerived2--")]
			public void DerivedRUCMethod () { }
		}

		[Kept]
		[KeptBaseType (typeof (Unsuppressed))]
		class SuppressedBaseWarningsOnDerived : Unsuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[ExpectedWarning ("IL2112", "--RUC on SuppressedBaseWarningsOnDerived")]
			[RequiresUnreferencedCode ("--RUC on SuppressedBaseWarningsOnDerived--")]
			public void DerivedRUCMethod () { }
		}

		[Kept]
		[KeptMember (".ctor()")]
		[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
		[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
		class AnnotatedAllSuppressed
		{
			[Kept]
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
			[UnconditionalSuppressMessage ("TrimAnalysis", "IL2114")]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
			public Type DAMTField;

			[Kept]
			[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
			[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
			[UnconditionalSuppressMessage ("TrimAnalysis", "IL2112")]
			[RequiresUnreferencedCode ("--RUC on AnnotatedAllSuppresed.RUCMethod--")]
			public static void RUCMethod () { }

			[Kept]
			[KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))]
			[UnconditionalSuppressMessage ("TrimAnalysis", "IL2114")]
			public void DAMTMethod (
				[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
				[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
				Type t
			)
			{ }
		}
	}
}