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

CompilerGeneratedCodeInPreservedAssemblyWithWarning.cs « DataFlow « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b66b0cd30929a4c870a455dec06b7e98266b9f8d (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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
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.DataFlow
{
	// Similar to CompilerGeneratedCodeInPreservedAssembly, but with warnings
	// produced while marking the compiler generated code.
	[SkipKeptItemsValidation]
	[ExpectedNoWarnings]
	[SetupLinkerArgument ("--enable-opt", "ipconstprop")]
	[SetupLinkerDescriptorFile ("CompilerGeneratedCodeInPreservedAssembly.xml")]
	class CompilerGeneratedCodeInPreservedAssemblyWithWarning
	{
		[ExpectedWarning ("IL2026", "--" + nameof (Inner) + "." + nameof (Inner.WithLocalFunctionInner) + "--")]
		[ExpectedWarning ("IL2026", "--" + nameof (WithLocalFunction) + "--")]
		public static void Main ()
		{
			Inner.WithLocalFunctionInner ();
			WithLocalFunction ();
		}

		class Inner
		{
			// In this case the compiler generated state will see the modified body,
			// and will not associate the local function with the user method.
			// Generic argument warnings from the local function will not be suppressed
			// by RUC on the user method.
			[RequiresUnreferencedCode ("--" + nameof (Inner) + "." + nameof (WithLocalFunctionInner) + "--")]
			public static void WithLocalFunctionInner ()
			{
				if (AlwaysFalse) {
					LocalWithWarning<int> ();
				}

				// https://github.com/dotnet/linker/issues/2937
				[ExpectedWarning ("IL2091", ProducedBy = ProducedBy.Trimmer)]
				void LocalWithWarning<T> ()
				{
					// Warning!
					RequiresAllOnT<T> ();
				}
			}
		}

		// In this case the compiler generated state will see the original body,
		// and will associate the local function with the user method.
		// Generic argument warnings from the local function will be suppressed
		// by RUC on the user method.
		[RequiresUnreferencedCode ("--" + nameof (WithLocalFunction) + "--")]
		public static void WithLocalFunction ()
		{
			if (AlwaysFalse) {
				LocalWithWarning<int> ();
			}

			// https://github.com/dotnet/linker/issues/2937
			void LocalWithWarning<T> ()
			{
				// No warning
				RequiresAllOnT<T> ();
			}
		}
		public static bool AlwaysFalse => false;
		static void RequiresAllOnT<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] T> () { }
	}
}