Skip to content

Run MethodOutParameterDataFlow tests in analyzer #101735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ public Task MemberTypesRelationships ()
return RunTest (nameof (MemberTypesRelationships));
}

[Fact]
public Task MethodOutParameterDataFlow ()
{
return RunTest ();
}

[Fact]
public Task MethodParametersDataFlow ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public Task MethodByRefParameterDataFlow ()
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task MethodOutParameterDataFlow ()
{
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task StaticInterfaceMethodDataflow ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void Main ()
TestInitializedReadFromOutParameter_PassedTwice ();
TestUninitializedReadFromOutParameter ();
TestInitializedReadFromOutParameter_MismatchOnOutput ();
TestInitializedReturnOutParameter_MismatchOnOutput ();
TestInitializedReadFromOutParameter_MismatchOnOutput_PassedTwice ();
TestInitializedReadFromOutParameter_MismatchOnInput ();
TestInitializedReadFromOutParameter_MismatchOnInput_PassedTwice ();
Expand Down Expand Up @@ -55,28 +56,36 @@ static void TestUninitializedReadFromOutParameter ()
typeWithMethods.RequiresPublicMethods ();
}

[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
static void TestInitializedReadFromOutParameter_MismatchOnOutput ()
{
Type typeWithMethods = null;
TryGetAnnotatedValue (out typeWithMethods);
typeWithMethods.RequiresPublicFields ();
}

// https://github.com/dotnet/linker/issues/2632
// This test should generate a warning since there's mismatch on annotations
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
[ExpectedWarning ("IL2068", nameof (TryGetAnnotatedValue), nameof (DynamicallyAccessedMemberTypes.PublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
static Type TestInitializedReturnOutParameter_MismatchOnOutput ()
{
Type typeWithMethods = null;
TryGetAnnotatedValue (out typeWithMethods);
return typeWithMethods;
}

// This test should generate a warning since there's mismatch on annotations
[ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
static void TestInitializedReadFromOutParameter_MismatchOnOutput_PassedTwice ()
{
Type typeWithMethods = null;
TryGetAnnotatedValueFromValue (typeWithMethods, out typeWithMethods);
typeWithMethods.RequiresPublicFields ();
}

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

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

[ExpectedWarning ("IL2067", "typeWithFields", nameof (TryGetAnnotatedValue))]
[ExpectedWarning ("IL2067", "typeWithFields", nameof (TryGetAnnotatedValue), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2632")]
static void TestPassingOutParameter_Mismatch ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] out Type typeWithFields)
{
TryGetAnnotatedValue (out typeWithFields);
Expand Down
Loading