diff --git a/src/linker/Linker.Steps/MarkStep.cs b/src/linker/Linker.Steps/MarkStep.cs index 789231f223f3..d7725b0e5aea 100644 --- a/src/linker/Linker.Steps/MarkStep.cs +++ b/src/linker/Linker.Steps/MarkStep.cs @@ -309,6 +309,10 @@ protected bool IsFullyPreserved (TypeDefinition type) internal void MarkEntireType (TypeDefinition type, bool includeBaseAndInterfaceTypes, in DependencyInfo reason) { + // Prevent cases where there's nothing on the stack (can happen when marking entire assemblies) + // In which case we would generate warnings with no source (hard to debug) + using var _ = _scopeStack.CurrentScope.Origin.MemberDefinition == null ? _scopeStack.PushScope (new MessageOrigin (type)) : null; + MarkEntireTypeInternal (type, includeBaseAndInterfaceTypes, reason); } @@ -325,17 +329,19 @@ void MarkEntireTypeInternal (TypeDefinition type, bool includeBaseAndInterfaceTy _entireTypesMarked[type] = includeBaseAndInterfaceTypes; + bool isDynamicDependencyReason = reason.Kind == DependencyKind.DynamicallyAccessedMember || reason.Kind == DependencyKind.DynamicDependency; + if (type.HasNestedTypes) { foreach (TypeDefinition nested in type.NestedTypes) - MarkEntireTypeInternal (nested, includeBaseAndInterfaceTypes, new DependencyInfo (DependencyKind.NestedType, type)); + MarkEntireTypeInternal (nested, includeBaseAndInterfaceTypes, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.NestedType, type)); } Annotations.Mark (type, reason); var baseTypeDefinition = _context.Resolve (type.BaseType); if (includeBaseAndInterfaceTypes && baseTypeDefinition != null) { - MarkEntireTypeInternal (baseTypeDefinition, true, new DependencyInfo (DependencyKind.BaseType, type)); + MarkEntireTypeInternal (baseTypeDefinition, true, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.BaseType, type)); } - MarkCustomAttributes (type, new DependencyInfo (DependencyKind.CustomAttribute, type)); + MarkCustomAttributes (type, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.CustomAttribute, type)); MarkTypeSpecialCustomAttributes (type); if (type.HasInterfaces) { @@ -352,27 +358,26 @@ void MarkEntireTypeInternal (TypeDefinition type, bool includeBaseAndInterfaceTy if (type.HasFields) { foreach (FieldDefinition field in type.Fields) { - MarkField (field, new DependencyInfo (DependencyKind.MemberOfType, type)); + MarkField (field, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.MemberOfType, type)); } } if (type.HasMethods) { foreach (MethodDefinition method in type.Methods) { Annotations.SetAction (method, MethodAction.ForceParse); - DependencyKind dependencyKind = (reason.Kind == DependencyKind.DynamicallyAccessedMember || reason.Kind == DependencyKind.DynamicDependency) ? reason.Kind : DependencyKind.MemberOfType; - MarkMethod (method, new DependencyInfo (dependencyKind, type)); + MarkMethod (method, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.MemberOfType, type)); } } if (type.HasProperties) { foreach (var property in type.Properties) { - MarkProperty (property, new DependencyInfo (DependencyKind.MemberOfType, type)); + MarkProperty (property, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.MemberOfType, type)); } } if (type.HasEvents) { foreach (var ev in type.Events) { - MarkEvent (ev, new DependencyInfo (DependencyKind.MemberOfType, type)); + MarkEvent (ev, new DependencyInfo (isDynamicDependencyReason ? reason.Kind : DependencyKind.MemberOfType, type)); } } } @@ -938,21 +943,21 @@ void MarkDynamicDependency (DynamicDependency dynamicDependency, IMemberDefiniti } } - MarkMembers (type, members, new DependencyInfo (DependencyKind.DynamicDependency, dynamicDependency.OriginalAttribute)); + MarkMembersVisibleToReflection (type, members, new DependencyInfo (DependencyKind.DynamicDependency, dynamicDependency.OriginalAttribute)); } - void MarkMembers (TypeDefinition typeDefinition, IEnumerable members, in DependencyInfo reason) + void MarkMembersVisibleToReflection (TypeDefinition typeDefinition, IEnumerable members, in DependencyInfo reason) { foreach (var member in members) { switch (member) { case TypeDefinition type: - MarkType (type, reason); + MarkTypeVisibleToReflection (type, type, reason); break; case MethodDefinition method: - MarkMethod (method, reason); + MarkMethodVisibleToReflection (method, reason); break; case FieldDefinition field: - MarkField (field, reason); + MarkFieldVisibleToReflection (field, reason); break; case PropertyDefinition property: MarkPropertyVisibleToReflection (property, reason); @@ -970,7 +975,6 @@ void MarkMembers (TypeDefinition typeDefinition, IEnumerable attrs) { switch (m.Identifier.ValueText) { - case "MethodWithDuplicateRequiresAttribute": - case "TestRequiresUnreferencedCodeOnlyThroughReflection": - case "TestRequiresInMethodFromCopiedAssembly": - case "TestRequiresThroughReflectionInMethodFromCopiedAssembly": // There is a discrepancy between the way linker and the analyzer represent the location of the error, // linker will point to the method caller and the analyzer will point to a line of code. // The TestTypeIsBeforeFieldInit scenario is supported by the analyzer, just the diagnostic message is different diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs index 04ba3fdcb3dd..e488f056add6 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs @@ -3,7 +3,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions { [AttributeUsage ( - AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Interface, + AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Event, AllowMultiple = true, Inherited = false)] public class ExpectedWarningAttribute : EnableLoggerAttribute diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs index e4a23ffa5b52..3eb2a7906df5 100644 --- a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs @@ -1,4 +1,5 @@ -using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; @@ -21,6 +22,8 @@ public static void Main () B.SameContext (); B.Broken (); B.Conditional (); + + TestRequiresInPreserveDependency (); } [KeptMember (".ctor()")] @@ -96,6 +99,20 @@ public NestedStruct (string name) Name = name; } } + + [Kept] + [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))] + [RequiresUnreferencedCode ("Message for --RequiresUnreferencedCodeInPreserveDependency--")] + static void RequiresUnreferencedCodeInPreserveDependency () + { + } + + [Kept] + [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeInPreserveDependency--")] + [PreserveDependency ("RequiresUnreferencedCodeInPreserveDependency")] + static void TestRequiresInPreserveDependency () + { + } } [KeptMember (".ctor()")] diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeInCopyAssembly.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeInCopyAssembly.cs index bce479e57dec..4e558f33fb3f 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeInCopyAssembly.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeInCopyAssembly.cs @@ -89,7 +89,6 @@ public interface IBaseInterface void MethodInBaseInterface (); } - [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--")] public interface IDerivedInterface : IBaseInterface { [RequiresUnreferencedCode ("Message for --IDerivedInterface.MethodInDerivedInterface--")] diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs index 3d3f0afdaf72..0e8231e9d1d0 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs @@ -4,7 +4,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Linq.Expressions; +using System.Runtime.InteropServices; using System.Text; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Helpers; @@ -13,10 +16,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability { - [SetupLinkerAction ("copyused", "lib")] + [SetupLinkerAction ("copy", "lib")] [SetupCompileBefore ("lib.dll", new[] { "Dependencies/RequiresUnreferencedCodeInCopyAssembly.cs" })] [KeptAllTypesAndMembersInAssembly ("lib.dll")] [SetupLinkAttributesFile ("RequiresUnreferencedCodeCapability.attributes.xml")] + [SetupLinkerDescriptorFile ("RequiresUnreferencedCodeCapability.descriptor.xml")] [SkipKeptItemsValidation] // Annotated members on a copied assembly should not produce any warnings // unless directly called or referenced through reflection. @@ -28,11 +32,15 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [LogDoesNotContain ("--UnusedVirtualMethod2--")] [LogDoesNotContain ("--IUnusedInterface.UnusedMethod--")] [LogDoesNotContain ("--UnusedImplementationClass.UnusedMethod--")] + // [LogDoesNotContain ("UnusedVirtualMethod2")] // https://github.com/mono/linker/issues/2106 + // [LogContains ("--RequiresUnreferencedCodeOnlyViaDescriptor--")] // https://github.com/mono/linker/issues/2103 + [ExpectedNoWarnings] public class RequiresUnreferencedCodeCapability { [ExpectedWarning ("IL2026", "--IDerivedInterface.MethodInDerivedInterface--", GlobalAnalysisOnly = true)] [ExpectedWarning ("IL2026", "--DynamicallyAccessedTypeWithRequiresUnreferencedCode.RequiresUnreferencedCode--", GlobalAnalysisOnly = true)] [ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequiresUnreferencedCode--", GlobalAnalysisOnly = true)] + [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--", GlobalAnalysisOnly = true)] public static void Main () { TestRequiresWithMessageOnlyOnMethod (); @@ -43,12 +51,14 @@ public static void Main () SuppressGenericParameters.Test (); TestDuplicateRequiresAttribute (); TestRequiresUnreferencedCodeOnlyThroughReflection (); + AccessedThroughReflectionOnGenericType.Test (); TestBaseTypeVirtualMethodRequiresUnreferencedCode (); TestTypeWhichOverridesMethodVirtualMethodRequiresUnreferencedCode (); TestTypeWhichOverridesMethodVirtualMethodRequiresUnreferencedCodeOnBase (); TestTypeWhichOverridesVirtualPropertyRequiresUnreferencedCode (); TestStaticCctorRequiresUnreferencedCode (); TestStaticCtorMarkingIsTriggeredByFieldAccess (); + TestStaticCtorMarkingIsTriggeredByFieldAccessOnExplicitLayout (); TestStaticCtorTriggeredByMethodCall (); TestTypeIsBeforeFieldInit (); TestDynamicallyAccessedMembersWithRequiresUnreferencedCode (typeof (DynamicallyAccessedTypeWithRequiresUnreferencedCode)); @@ -62,6 +72,13 @@ public static void Main () TestThatTrailingPeriodIsAddedToMessage (); TestThatTrailingPeriodIsNotDuplicatedInWarningMessage (); RequiresOnAttribute.Test (); + RequiresOnGenerics.Test (); + CovariantReturnViaLdftn.Test (); + AccessThroughSpecialAttribute.Test (); + AccessThroughPInvoke.Test (); + OnEventMethod.Test (); + AccessThroughNewConstraint.Test (); + AccessThroughLdToken.Test (); } [ExpectedWarning ("IL2026", "Message for --RequiresWithMessageOnly--.")] @@ -234,7 +251,7 @@ static void TestDuplicateRequiresAttribute () // The second attribute is added through link attribute XML [RequiresUnreferencedCode ("Message for --MethodWithDuplicateRequiresAttribute--")] - [ExpectedWarning ("IL2027", "RequiresUnreferencedCodeAttribute", nameof (MethodWithDuplicateRequiresAttribute))] + [ExpectedWarning ("IL2027", "RequiresUnreferencedCodeAttribute", nameof (MethodWithDuplicateRequiresAttribute), GlobalAnalysisOnly = true)] static void MethodWithDuplicateRequiresAttribute () { } @@ -244,7 +261,7 @@ static void RequiresUnreferencedCodeOnlyThroughReflection () { } - [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeOnlyThroughReflection--")] + [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeOnlyThroughReflection--", GlobalAnalysisOnly = true)] static void TestRequiresUnreferencedCodeOnlyThroughReflection () { typeof (RequiresUnreferencedCodeCapability) @@ -252,6 +269,22 @@ static void TestRequiresUnreferencedCodeOnlyThroughReflection () .Invoke (null, new object[0]); } + class AccessedThroughReflectionOnGenericType + { + [RequiresUnreferencedCode ("Message for --GenericType.RequiresUnreferencedCodeOnlyThroughReflection--")] + public static void RequiresUnreferencedCodeOnlyThroughReflection () + { + } + + [ExpectedWarning ("IL2026", "--GenericType.RequiresUnreferencedCodeOnlyThroughReflection--", GlobalAnalysisOnly = true)] + public static void Test () + { + typeof (AccessedThroughReflectionOnGenericType) + .GetMethod (nameof (RequiresUnreferencedCodeOnlyThroughReflection)) + .Invoke (null, new object[0]); + } + } + class BaseType { [RequiresUnreferencedCode ("Message for --BaseType.VirtualMethodRequiresUnreferencedCode--")] @@ -343,6 +376,20 @@ static void TestStaticCtorMarkingIsTriggeredByFieldAccess () var x = StaticCtorTriggeredByFieldAccess.field + 1; } + struct StaticCCtorForFieldAccess + { + [RequiresUnreferencedCode ("Message for --StaticCCtorForFieldAccess.cctor--")] + static StaticCCtorForFieldAccess () { } + + public static int field; + } + + [ExpectedWarning ("IL2026", "--StaticCCtorForFieldAccess.cctor--")] + static void TestStaticCtorMarkingIsTriggeredByFieldAccessOnExplicitLayout () + { + StaticCCtorForFieldAccess.field = 0; + } + class TypeIsBeforeFieldInit { public static int field = AnnotatedMethod (); @@ -441,14 +488,18 @@ static void TestCovariantReturnCallOnDerived () tmp.GetRequiresUnreferencedCode (); } - [ExpectedWarning ("IL2026", "--Method--")] + // https://github.com/mono/linker/issues/2107 + // Doesn't work in the analyzer because the test infra for analyzer will not build the second assembly + // and provide it as a ref assembly to the compilation - so the analyzer actually sees the below + // as errors (missing assembly). + [ExpectedWarning ("IL2026", "--Method--", GlobalAnalysisOnly = true)] static void TestRequiresInMethodFromCopiedAssembly () { var tmp = new RequiresUnreferencedCodeInCopyAssembly (); tmp.Method (); } - [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--")] + [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--", GlobalAnalysisOnly = true)] static void TestRequiresThroughReflectionInMethodFromCopiedAssembly () { typeof (RequiresUnreferencedCodeInCopyAssembly) @@ -506,6 +557,20 @@ public AttributeWhichRequiresUnreferencedCodeAttribute () } } + class AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute : Attribute + { + public AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute () + { + } + + public bool PropertyWhichRequires { + get => false; + + [RequiresUnreferencedCode ("--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")] + set { } + } + } + [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")] class GenericTypeWithAttributedParameter<[AttributeWhichRequiresUnreferencedCode] T> { @@ -524,25 +589,34 @@ static void TestRequiresOnAttributeOnGenericParameter () // https://github.com/mono/linker/issues/2094 - should be supported by the analyzer [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--", GlobalAnalysisOnly = true)] + [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")] [AttributeWhichRequiresUnreferencedCode] + [AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)] class TypeWithAttributeWhichRequires { } // https://github.com/mono/linker/issues/2094 - should be supported by the analyzer [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--", GlobalAnalysisOnly = true)] + [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")] [AttributeWhichRequiresUnreferencedCode] + [AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)] static void MethodWithAttributeWhichRequires () { } [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")] + [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")] [AttributeWhichRequiresUnreferencedCode] + [AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)] static int _fieldWithAttributeWhichRequires; [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")] + [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")] [AttributeWhichRequiresUnreferencedCode] + [AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)] static bool PropertyWithAttributeWhichRequires { get; set; } [AttributeWhichRequiresUnreferencedCode] + [AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)] [RequiresUnreferencedCode ("--MethodWhichRequiresWithAttributeWhichRequires--")] static void MethodWhichRequiresWithAttributeWhichRequires () { } @@ -562,5 +636,151 @@ public static void Test () TestMethodWhichRequiresWithAttributeWhichRequires (); } } + + [RequiresUnreferencedCode ("Message for --RequiresUnreferencedCodeOnlyViaDescriptor--")] + static void RequiresUnreferencedCodeOnlyViaDescriptor () + { + } + + class RequiresOnGenerics + { + class GenericWithStaticMethod + { + [RequiresUnreferencedCode ("Message for --GenericTypeWithStaticMethodWhichRequires--")] + public static void GenericTypeWithStaticMethodWhichRequires () { } + } + + [ExpectedWarning ("IL2026", "--GenericTypeWithStaticMethodWhichRequires--")] + public static void GenericTypeWithStaticMethodViaLdftn () + { + var _ = new Action (GenericWithStaticMethod.GenericTypeWithStaticMethodWhichRequires); + } + + public static void Test () + { + GenericTypeWithStaticMethodViaLdftn (); + } + } + + class CovariantReturnViaLdftn + { + abstract class Base + { + [RequiresUnreferencedCode ("Message for --CovariantReturnViaLdftn.Base.GetRequiresUnreferencedCode--")] + public abstract BaseReturnType GetRequiresUnreferencedCode (); + } + + class Derived : Base + { + [RequiresUnreferencedCode ("Message for --CovariantReturnViaLdftn.Derived.GetRequiresUnreferencedCode--")] + public override DerivedReturnType GetRequiresUnreferencedCode () + { + return null; + } + } + + [ExpectedWarning ("IL2026", "--CovariantReturnViaLdftn.Derived.GetRequiresUnreferencedCode--")] + public static void Test () + { + var tmp = new Derived (); + var _ = new Func (tmp.GetRequiresUnreferencedCode); + } + } + + class AccessThroughSpecialAttribute + { + [ExpectedWarning ("IL2026", "--DebuggerProxyType.Method--")] + [DebuggerDisplay ("Some{*}value")] + class TypeWithDebuggerDisplay + { + [RequiresUnreferencedCode ("Message for --DebuggerProxyType.Method--")] + public void Method () + { + } + } + + public static void Test () + { + var _ = new TypeWithDebuggerDisplay (); + } + } + + class AccessThroughPInvoke + { + class PInvokeReturnType + { + [RequiresUnreferencedCode ("Message for --PInvokeReturnType.ctor--")] + public PInvokeReturnType () { } + } + + // https://github.com/mono/linker/issues/2116 + [ExpectedWarning ("IL2026", "--PInvokeReturnType.ctor--", GlobalAnalysisOnly = true)] + [DllImport ("nonexistent")] + static extern PInvokeReturnType PInvokeReturnsType (); + + // Analyzer doesn't support IL2050 yet + [ExpectedWarning ("IL2050", GlobalAnalysisOnly = true)] + public static void Test () + { + PInvokeReturnsType (); + } + } + + class OnEventMethod + { + [ExpectedWarning ("IL2026", "--EventToTestRemove.remove--")] + static event EventHandler EventToTestRemove { + add { } + [RequiresUnreferencedCode ("Message for --EventToTestRemove.remove--")] + remove { } + } + + [ExpectedWarning ("IL2026", "--EventToTestAdd.add--")] + static event EventHandler EventToTestAdd { + [RequiresUnreferencedCode ("Message for --EventToTestAdd.add--")] + add { } + remove { } + } + + public static void Test () + { + EventToTestRemove += (sender, e) => { }; + EventToTestAdd -= (sender, e) => { }; + } + } + + class AccessThroughNewConstraint + { + class NewConstrainTestType + { + [RequiresUnreferencedCode ("Message for --NewConstrainTestType.ctor--")] + public NewConstrainTestType () { } + } + + static void GenericMethod () where T : new() { } + + // https://github.com/mono/linker/issues/2117 + [ExpectedWarning ("IL2026", "--NewConstrainTestType.ctor--", GlobalAnalysisOnly = true)] + public static void Test () + { + GenericMethod (); + } + } + + class AccessThroughLdToken + { + static bool PropertyWithLdToken { + [RequiresUnreferencedCode ("Message for --PropertyWithLdToken.get--")] + get { + return false; + } + } + + [ExpectedWarning ("IL2026", "--PropertyWithLdToken.get--")] + public static void Test () + { + Expression> getter = () => PropertyWithLdToken; + } + } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.descriptor.xml b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.descriptor.xml new file mode 100644 index 000000000000..28fdf2f42a2a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.descriptor.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file