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

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

Closed
Tracked by #2273
sbomer opened this issue Oct 5, 2021 · 1 comment
Closed
Tracked by #2273

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

sbomer opened this issue Oct 5, 2021 · 1 comment
Assignees

Comments

@sbomer
Copy link
Member

sbomer commented Oct 5, 2021

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.

@sbomer
Copy link
Member Author

sbomer commented Oct 29, 2021

We will want to track both typeof(Foo) where Foo is a known type, and typeof(T) where T is a generic parameter. However, since we don't have the binding logic that produces warnings for typeof(Foo) values yet, I think it would be acceptable not to track typeof(Foo) for now. In that case I think this particular issue could be fixed by only returning typeOf.TypeOperand when the type operand in the typeof operation is an ITypeParameterSymbol.

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

2 participants