-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
DAM on type is supposed to ensure that GetType called on that type or any derived type will satisfy the DAM annotations. In this example, d.GetType() should keep public methods on the base type and produce a warning for the RUC method.
using System.Diagnostics.CodeAnalysis;
class Program {
public static void Main() {
RequirePublicMethods(d.GetType());
}
static D d = new();
static void RequirePublicMethods([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t) {}
}
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
class B {
[RequiresUnreferencedCode("M")]
public virtual void M() {} // There should be a warning about reflection access (through DAM-on-type) to M
}
class D : B {}ProcessTypeGetTypeDataflow gets called for the derived type D, but nothing applies the annotations on B. This logic doesn't do it because it assumes B's annotations were already applied, and so doesn't keep B's members while processing D:
runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
Lines 147 to 156 in 4dd997d
| if (type.HasBaseType) | |
| { | |
| var baseAnnotation = flowAnnotations.GetTypeAnnotation(type.BaseType); | |
| var annotationToApplyToBase = Annotations.GetMissingMemberTypes(annotation, baseAnnotation); | |
| // Apply any annotations that didn't exist on the base type to the base type. | |
| // This may produce redundant warnings when the annotation is DAMT.All or DAMT.PublicConstructors and the base already has a | |
| // subset of those annotations. | |
| reflectionMarker.MarkTypeForDynamicallyAccessedMembers(origin, type.BaseType, annotationToApplyToBase, type.GetDisplayName(), declaredOnly: false); | |
| } |
Metadata
Metadata
Assignees
Labels
area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Type
Projects
Status
No status