Skip to content
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 @@ -14,10 +14,7 @@ internal static class GenericArgumentDataFlow
{
public static void ProcessGenericArgumentDataFlow (Location location, INamedTypeSymbol type, Action<Diagnostic> reportDiagnostic)
{
while (type is { IsGenericType: true }) {
ProcessGenericArgumentDataFlow (location, type.TypeArguments, type.TypeParameters, reportDiagnostic);
type = type.ContainingType;
}
ProcessGenericArgumentDataFlow (location, type.TypeArguments, type.TypeParameters, reportDiagnostic);
}

public static void ProcessGenericArgumentDataFlow (Location location, IMethodSymbol method, Action<Diagnostic> reportDiagnostic)
Expand Down Expand Up @@ -58,7 +55,7 @@ static void ProcessGenericArgumentDataFlow (

public static bool RequiresGenericArgumentDataFlow (INamedTypeSymbol type)
{
while (type is { IsGenericType: true }) {
if (type.IsGenericType) {
if (RequiresGenericArgumentDataFlow (type.TypeParameters))
return true;

Expand All @@ -67,8 +64,6 @@ public static bool RequiresGenericArgumentDataFlow (INamedTypeSymbol type)
&& RequiresGenericArgumentDataFlow (namedTypeSymbol))
return true;
}

type = type.ContainingType;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ public Task RequiresInLibraryAssembly ()
return RunTest ();
}

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

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

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

[Fact]
public Task StaticInterfaceMethodDataflow ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static void Main ()

TestNoWarningsInRUCMethod<TestType> ();
TestNoWarningsInRUCType<TestType, TestType> ();
TestGenericParameterFlowsToNestedType.Test ();
}

static void TestSingleGenericParameterOnType ()
Expand Down Expand Up @@ -850,59 +849,6 @@ static void TestNoWarningsInRUCType<T, U> ()
rucType.VirtualMethodRequiresPublicMethods<T> ();
}

class TestGenericParameterFlowsToNestedType
{
class Generic<T> {
[ExpectedWarning ("IL2091")]
public T CallNestedMethod () => GenericRequires<T>.Nested.Method ();

[ExpectedWarning ("IL2091")]
public T AccessNestedField () => GenericRequires<T>.Nested.Field;

[ExpectedWarning ("IL2091")]
public T AccessNestedProperty () => GenericRequires<T>.Nested.Property;

[ExpectedWarning ("IL2091")]
public void AccessNestedEvent () => GenericRequires<T>.Nested.Event += null;

[ExpectedWarning ("IL2091")]
public void UseNestedTypeArgument () {
new Generic<GenericRequires<T>.Nested> ();
}

[ExpectedWarning ("IL2091")]
public class DerivedFromNestedType : GenericRequires<T>.Nested
{
[ExpectedWarning ("IL2091")]
public DerivedFromNestedType () {
}
}
}

class GenericRequires<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> {
public class Nested {
public static T? Method () => default;

public static T? Field = default;

public static T? Property { get; set; } = default;

public static event Action<T>? Event;
}
}

public static void Test ()
{
var instance = new Generic<string> ();
instance.CallNestedMethod ();
instance.AccessNestedField ();
instance.AccessNestedProperty ();
instance.AccessNestedEvent ();
instance.UseNestedTypeArgument ();
new Generic<string>.DerivedFromNestedType ();
}
}

[RequiresUnreferencedCode ("message")]
public class RUCTypeRequiresPublicFields<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
Expand Down