blob: 974947e797c03233b3abe3087262cbf5957e92a8 (
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
|
// 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.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
{
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
class MethodByRefParameterDataFlow
{
public static void Main ()
{
Type typeWithMethods = _fieldWithMethods;
TestAssignStaticToAnnotatedRefParameter (ref typeWithMethods);
TestAssignParameterToAnnotatedRefParameter (ref typeWithMethods, typeof (TestType));
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
static Type _fieldWithMethods = null;
[ExpectedWarning ("IL2026", "Message for --TestType.Requires--")]
// https://github.com/dotnet/linker/issues/2158
// The type.GetMethods call generates a warning because we're not able to correctly track the value of the "this".
// (there's a ldind.ref insruction here which we currently don't handle and the "this" becomes unknown)
[ExpectedWarning ("IL2065")]
static void TestAssignStaticToAnnotatedRefParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] ref Type type)
{
type = typeof (TestTypeWithRequires);
type.GetMethods (); // Should not warn
}
// The warning message is REALLY confusing (basically wrong) since it talks about "calling the method with wrong argument"
// which is definitely not the case here.
[ExpectedWarning ("IL2067", "typeWithFields")]
// https://github.com/dotnet/linker/issues/2158
// The type.GetMethods call generates a warning because we're not able to correctly track the value of the "this".
// (there's a ldind.ref insruction here which we currently don't handle and the "this" becomes unknown)
[ExpectedWarning ("IL2065")]
static void TestAssignParameterToAnnotatedRefParameter (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] ref Type type,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type typeWithFields)
{
type = typeWithFields; // Should warn
type.GetMethods (); // Should not warn
}
class TestTypeWithRequires
{
[RequiresUnreferencedCode ("Message for --TestType.Requires--")]
public static void Requires () { }
}
class TestType
{
}
}
}
|