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 @@ -22,6 +22,7 @@ public static void Main ()
{
TestRequiresOnlyThroughReflection ();
AccessedThroughReflectionOnGenericType<TestType>.Test ();
AccessedThroughGenericParameterAnnotation.Test ();
AccessThroughSpecialAttribute.Test ();
AccessThroughPInvoke.Test ();
AccessThroughNewConstraint.Test<TestType> ();
Expand Down Expand Up @@ -73,6 +74,59 @@ public static void Test ()
}
}

class AccessedThroughGenericParameterAnnotation
{
class TypeWithRequiresMethod
{
[RequiresUnreferencedCode("--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--")]
[RequiresDynamicCode ("--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--")]
[RequiresAssemblyFiles ("--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--")]
public static void MethodWhichRequires () { }
}

class TypeWithPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T>
{
public TypeWithPublicMethods () { }
}

[ExpectedWarning ("IL2026", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--")]
[ExpectedWarning ("IL3002", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
[ExpectedWarning ("IL3050", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
static void TestAccessOnGenericType ()
{
new TypeWithPublicMethods<TypeWithRequiresMethod> ();
}

static void MethodWithPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> () { }

[ExpectedWarning ("IL2026", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--")]
[ExpectedWarning ("IL3002", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
[ExpectedWarning ("IL3050", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
static void TestAccessOnGenericMethod ()
{
MethodWithPublicMethods<TypeWithRequiresMethod> ();
}

static void MethodWithPublicMethodsInference<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> (T instance) { }

// https://github.com/dotnet/runtime/issues/86032
// IL2026 should be produced by the analyzer as well, but it has a bug around inferred generic arguments
[ExpectedWarning ("IL2026", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
[ExpectedWarning ("IL3002", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
[ExpectedWarning ("IL3050", "--AccessedThroughGenericParameterAnnotation.TypeWithRequiresMethod.MethodWhichRequires--", ProducedBy = Tool.NativeAot)]
static void TestAccessOnGenericMethodWithInferenceOnMethod ()
{
MethodWithPublicMethodsInference (new TypeWithRequiresMethod ());
}

public static void Test ()
{
TestAccessOnGenericType ();
TestAccessOnGenericMethod ();
TestAccessOnGenericMethodWithInferenceOnMethod ();
}
}

class AccessThroughSpecialAttribute
{
// https://github.com/dotnet/linker/issues/1873
Expand Down
Loading