Skip to content

[DAM analyzer] Spurious warnings for typeof(Foo) arguments #2308

Closed
@sbomer

Description

@sbomer
public static void Main() {
    M(typeof(C));
}

// warning IL2082: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.M(Type)'.
// The implicit 'this' argument of method 'C.Main()' does not have matching annotations.
// The source value must declare at least the same requirements as those declared on the target location it is assigned to.
private static void M([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) {}

@mateoatr I think the typeof case here is causing the extra warning:

ITypeOfOperation typeOf => typeOf.TypeOperand,

I think the intention was to support typeof(T) flowing into an annotated location where T references a generic parameter. Unfortunately it produces unexpected warnings in cases like the above. Discovered while adding shared tests as part of #2307.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions