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

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>2022-05-02 22:15:42 +0300
committerGitHub <noreply@github.com>2022-05-02 22:15:42 +0300
commit05a3b652d525acaac1307221b62db979d0108692 (patch)
treea022115eb1dfde9ec5ba2b1dc3e6acf4aa6b73c9 /test/Mono.Linker.Tests.Cases
parent2375cba1a60713f83da1ba09c44faa17e9ad432c (diff)
Add ability for the analyzer to recognize const fields (#2774)
This means the value of the fields is tracked as a const value instead of a field reference. This is to support some additional code patterns as well as align the behavior with the linker. Compiler will inline the const fields into the IL effectively removing the field refernce in these cases and linker only sees the constant. So ideally the analyzer should have a similar behavior.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs17
1 files changed, 16 insertions, 1 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
index dff625716..ef58eac31 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
@@ -34,6 +34,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestStringEmpty ();
TypeWithWarnings.Test ();
+ OverConstTypeName.Test ();
// TODO:
// Test multi-value returns
@@ -163,7 +164,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeWithWarnings
{
-
[RequiresUnreferencedCode ("--Method1--")]
public void Method1 () { }
@@ -179,6 +179,21 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
+ class OverConstTypeName
+ {
+ private const string s_ConstTypeName = "Mono.Linker.Tests.Cases.DataFlow." + nameof (GetTypeDataFlow) + "+" + nameof (OverConstTypeName);
+
+ [RequiresUnreferencedCode ("--Method1--")]
+ public void Method1 () { }
+
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2026", "--Method1--", ProducedBy = ProducedBy.Trimmer)]
+ public static void Test ()
+ {
+ Type.GetType (s_ConstTypeName).RequiresPublicMethods ();
+ }
+ }
+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
private static string GetStringTypeWithPublicParameterlessConstructor ()
{