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:
authorSven Boemer <sbomer@gmail.com>2022-05-31 22:55:22 +0300
committerGitHub <noreply@github.com>2022-05-31 22:55:22 +0300
commit6f57bf9ef26214f86bb5c9532a2abbdce2a12c6d (patch)
tree85ad535008b905fb5e80b4bde457fa6e07af2bc9 /test/Mono.Linker.Tests.Cases
parent79b5653ccfd0663790b4dc4efe65c1285ede73fc (diff)
Don't crash analyzer for ref-return assignment (#2810)
* Don't crash analyzer for ref-return assignment * Same for flow capture references * Adjust tests after merge * PR feedback Add issue links to tests
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefReturnDataFlow.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefReturnDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefReturnDataFlow.cs
index dc1783482..e4c7b75a9 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefReturnDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefReturnDataFlow.cs
@@ -17,6 +17,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
ReturnAnnotatedTypeReferenceAsUnannotated ();
AssignToAnnotatedTypeReference ();
+ AssignDirectlyToAnnotatedTypeReference ();
+ AssignToCapturedAnnotatedTypeReference ();
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
@@ -40,6 +42,29 @@ namespace Mono.Linker.Tests.Cases.DataFlow
_annotatedField.GetMethods (); // Doesn't warn, but now contains typeof(TestType) - no warning here is correct
}
+ // Same as above for IL analysis, but this looks different to the Roslyn analyzer.
+ // https://github.com/dotnet/linker/issues/2158
+ [ExpectedWarning ("IL2026", "Message for --TestType.Requires--", ProducedBy = ProducedBy.Trimmer)]
+ static void AssignDirectlyToAnnotatedTypeReference ()
+ {
+ ReturnAnnotatedTypeReferenceAsAnnotated () = typeof (TestTypeWithRequires);
+ _annotatedField.GetMethods ();
+ }
+
+ // https://github.com/dotnet/linker/issues/2158
+ [ExpectedWarning ("IL2073", nameof (GetWithPublicFields), ProducedBy = ProducedBy.Trimmer)]
+ static void AssignToCapturedAnnotatedTypeReference ()
+ {
+ // In this testcase, the Roslyn analyzer sees an assignment to a flow-capture reference.
+ ReturnAnnotatedTypeReferenceAsAnnotated () = GetWithPublicMethods () ?? GetWithPublicFields ();
+ }
+
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ static Type GetWithPublicMethods () => null;
+
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+ static Type GetWithPublicFields () => null;
+
public class TestTypeWithRequires
{
[RequiresUnreferencedCode ("Message for --TestType.Requires--")]