MakeGenericMethod warning about mismatched annotations is wrong
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
```C#
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`](https://github.com/mono/linker/blob/e1c0c83d24d619ba37cdfc8bd7f8c8ebaf9f309b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs#L1922). 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.