dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.95k stars 4.65k forks source link

ILLink analyzer doesn't warn for invalid annotations in top-level methods #101215

Open sbomer opened 4 months ago

sbomer commented 4 months ago

DynamicallyAccessedMembers annotations are not supported for arbitrary types. The ILLink analyzer normally produces IL2098 warnings when the annotations are applied to unsupported types, but this isn't working for top-level methods:

using System.Diagnostics.CodeAnalysis;

RequireAll(GetFoo());

// This should warn
static void RequireAll([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Foo f) {}

static Foo GetFoo() => new Foo();

class Foo {}
dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

sbomer commented 3 months ago

This is blocked on https://github.com/dotnet/roslyn/issues/14061. I can't find a way to register a symbol action in the analyzer that gets called for top-level methods. I tried adding a RegisterSymbolAction for SymbolKind.Parameter, but that faces the same problem as mentioned in https://github.com/dotnet/roslyn/issues/14061#issuecomment-249438327.