Skip to content

Commit 9e678f6

Browse files
authored
Run MethodOutParameterDataFlow tests in analyzer (#101735)
And add a testcase to cover IL2068. This just ensures that this particular testcase runs without allowMissingWarnings for the analyzer, and adds one more testcase to track the specific missing warning that was encountered in #101203 (tracked in #101734).
1 parent 0d6868f commit 9e678f6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs

+6
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ public Task MemberTypesRelationships ()
289289
return RunTest (nameof (MemberTypesRelationships));
290290
}
291291

292+
[Fact]
293+
public Task MethodOutParameterDataFlow ()
294+
{
295+
return RunTest ();
296+
}
297+
292298
[Fact]
293299
public Task MethodParametersDataFlow ()
294300
{

src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/DataFlowTests.g.cs

-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ public Task MethodByRefParameterDataFlow ()
2525
return RunTest (allowMissingWarnings: true);
2626
}
2727

28-
[Fact]
29-
public Task MethodOutParameterDataFlow ()
30-
{
31-
return RunTest (allowMissingWarnings: true);
32-
}
33-
3428
[Fact]
3529
public Task StaticInterfaceMethodDataflow ()
3630
{

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodOutParameterDataFlow.cs

+16-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void Main ()
1919
TestInitializedReadFromOutParameter_PassedTwice ();
2020
TestUninitializedReadFromOutParameter ();
2121
TestInitializedReadFromOutParameter_MismatchOnOutput ();
22+
TestInitializedReturnOutParameter_MismatchOnOutput ();
2223
TestInitializedReadFromOutParameter_MismatchOnOutput_PassedTwice ();
2324
TestInitializedReadFromOutParameter_MismatchOnInput ();
2425
TestInitializedReadFromOutParameter_MismatchOnInput_PassedTwice ();
@@ -55,28 +56,36 @@ static void TestUninitializedReadFromOutParameter ()
5556
typeWithMethods.RequiresPublicMethods ();
5657
}
5758

58-
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
59+
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
5960
static void TestInitializedReadFromOutParameter_MismatchOnOutput ()
6061
{
6162
Type typeWithMethods = null;
6263
TryGetAnnotatedValue (out typeWithMethods);
6364
typeWithMethods.RequiresPublicFields ();
6465
}
6566

66-
// https://github.com/dotnet/linker/issues/2632
6767
// This test should generate a warning since there's mismatch on annotations
68-
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
68+
[ExpectedWarning ("IL2068", nameof (TryGetAnnotatedValue), nameof (DynamicallyAccessedMemberTypes.PublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
69+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
70+
static Type TestInitializedReturnOutParameter_MismatchOnOutput ()
71+
{
72+
Type typeWithMethods = null;
73+
TryGetAnnotatedValue (out typeWithMethods);
74+
return typeWithMethods;
75+
}
76+
77+
// This test should generate a warning since there's mismatch on annotations
78+
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
6979
static void TestInitializedReadFromOutParameter_MismatchOnOutput_PassedTwice ()
7080
{
7181
Type typeWithMethods = null;
7282
TryGetAnnotatedValueFromValue (typeWithMethods, out typeWithMethods);
7383
typeWithMethods.RequiresPublicFields ();
7484
}
7585

76-
// https://github.com/dotnet/linker/issues/2632
7786
// This warning should not be generated, the value of typeWithMethods should have PublicMethods
7887
// after the call with out parameter.
79-
[ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Analyzer, "")]
88+
[ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Analyzer, "https://github.com/dotnet/linker/issues/2632")]
8089
static void TestInitializedReadFromOutParameter_MismatchOnInput ()
8190
{
8291
Type typeWithMethods = GetTypeWithFields ();
@@ -86,10 +95,9 @@ static void TestInitializedReadFromOutParameter_MismatchOnInput ()
8695
}
8796

8897
[ExpectedWarning ("IL2072", nameof (TryGetAnnotatedValueFromValue))]
89-
// https://github.com/dotnet/linker/issues/2632
9098
// This warning should not be generated, the value of typeWithMethods should have PublicMethods
9199
// after the call with out parameter.
92-
[ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Analyzer, "")]
100+
[ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Analyzer, "https://github.com/dotnet/linker/issues/2632")]
93101
static void TestInitializedReadFromOutParameter_MismatchOnInput_PassedTwice ()
94102
{
95103
Type typeWithMethods = GetTypeWithFields ();
@@ -103,7 +111,7 @@ static void TestPassingOutParameter ([DynamicallyAccessedMembers (DynamicallyAcc
103111
TryGetAnnotatedValue (out typeWithMethods);
104112
}
105113

106-
[ExpectedWarning ("IL2067", "typeWithFields", nameof (TryGetAnnotatedValue))]
114+
[ExpectedWarning ("IL2067", "typeWithFields", nameof (TryGetAnnotatedValue), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
107115
static void TestPassingOutParameter_Mismatch ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] out Type typeWithFields)
108116
{
109117
TryGetAnnotatedValue (out typeWithFields);

0 commit comments

Comments
 (0)