Skip to content
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

Avoid redundant warnings for base members with DAM on type #2175

Closed
sbomer opened this issue Jul 27, 2021 · 1 comment
Closed

Avoid redundant warnings for base members with DAM on type #2175

sbomer opened this issue Jul 27, 2021 · 1 comment

Comments

@sbomer
Copy link
Member

sbomer commented Jul 27, 2021

The current behavior of DAM on types is that any subtype (including itself) of the DAM-annotated type will produce warnings for all members which aren't safe to access via reflection, including members declared on the derived type itself, and members declared on any base types.

This is necessary in cases like #2136 (comment) where some unannotated base type has reflection-unsafe members. But the warnings about base type members are redundant in cases when the base type already has the same DAM annotation (which would already produce this warning on the base type).

For example:

[DAM(DynamicallyAccessedMemberTypes.PublicMethods)]
class Base {
	[RUC("RUC")]
	public static void Method() {}
}

// ILLink : Trim analysis warning IL2026: Derived: Using method 'Base.Method()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. RUC.
// ILLink : Trim analysis warning IL2026: Derived: Using method 'Derived.MyMethod()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. RUC.
class Derived : Base {
	[RUC("RUC")]
	public static void MyMethod() {}
}

We should avoid producing these redundant warnings. In the example the warning about Base.Method is unnecessary as this will already warn elsewhere (with the fix for #2162, on the base type). Note that the warning codes and locations are changing in #2162.

@sbomer
Copy link
Member Author

sbomer commented Aug 10, 2021

Fixed in #2191.

Note that explicitly re-declared DAM on a type will still warn about base methods, for example:

[DAM(DynamicallyAccessedMemberTypes.PublicMethods)]
class Base {
    [RUC("RUC")]
    public static void Method() {}
}

// IL2113: Derived: 'DynamicallyAccessedMembersAttribute' on 'AnnotatedType' or one of its base types references 'Base.Method()' which requires unreferenced code. Using this member is trim unsafe.
[DAM(DynamicallyAccessedMemberTypes.PublicMethods)]
class Derived : Base {}

@sbomer sbomer closed this as completed Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant