Skip to content

MakeGenericMethod warning about mismatched annotations is wrong #2144

Open
@vitek-karas

Description

@vitek-karas
void GenericMethod<[DynamicallyAccessedMembers(PublicMethods)] T>() {}

void Test(Type type)
{
    // IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 
    // MakeGenericMethod'. The parameter 'type' of method 'Test' 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.
    typeof(TestType).GetMethod("GenericMethod").MakeGenericMethod(type);
}

The problem is that we pass the MethodDefinition as the "target" of the annotation match in AnalyzeGenericInstantiationTypeArray. We should pass the generic parameter instead.

This will hit a TODO here:
https://github.com/mono/linker/blob/e1c0c83d24d619ba37cdfc8bd7f8c8ebaf9f309b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs#L2104

These should be removed and tests validated for these (we should already have tests covering the scenarios, we just need to update them to the new warning code).

This needs to be fixed in 6 as it changes the warning code reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions