Skip to content

MakeGenericMethod shouldn't cause IL2060 warning if the specified method doesn't have ILLinker annotations #1727

@eerhardt

Description

@eerhardt

The following code in System.Text.RegularExpressions.RegexCompiler is causing IL2060 warnings:

private static readonly MethodInfo s_memoryMarshalGetReference = typeof(MemoryMarshal).GetMethod("GetReference", new Type[] { typeof(ReadOnlySpan<>).MakeGenericType(Type.MakeGenericMethodParameter(0)) })!.MakeGenericMethod(typeof(char));
private static readonly MethodInfo s_spanIndexOf = typeof(MemoryExtensions).GetMethod("IndexOf", new Type[] { typeof(ReadOnlySpan<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), Type.MakeGenericMethodParameter(0) })!.MakeGenericMethod(typeof(char));
private static readonly MethodInfo s_spanIndexOfAnyCharChar = typeof(MemoryExtensions).GetMethod("IndexOfAny", new Type[] { typeof(ReadOnlySpan<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), Type.MakeGenericMethodParameter(0), Type.MakeGenericMethodParameter(0) })!.MakeGenericMethod(typeof(char));
private static readonly MethodInfo s_spanIndexOfAnyCharCharChar = typeof(MemoryExtensions).GetMethod("IndexOfAny", new Type[] { typeof(ReadOnlySpan<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), Type.MakeGenericMethodParameter(0), Type.MakeGenericMethodParameter(0), Type.MakeGenericMethodParameter(0) })!.MakeGenericMethod(typeof(char));
RegexCompiler.cs(59,9): Trim analysis warning IL2060: System.Text.RegularExpressions.RegexCompiler..cctor(): Call to `System.Reflection.MethodInfo.MakeGenericMethod(Type[])` can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [C:\git\runtime\src\libraries\src.proj]
RegexCompiler.cs(60,9): Trim analysis warning IL2060: System.Text.RegularExpressions.RegexCompiler..cctor(): Call to `System.Reflection.MethodInfo.MakeGenericMethod(Type[])` can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [C:\git\runtime\src\libraries\src.proj]
RegexCompiler.cs(61,9): Trim analysis warning IL2060: System.Text.RegularExpressions.RegexCompiler..cctor(): Call to `System.Reflection.MethodInfo.MakeGenericMethod(Type[])` can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [C:\git\runtime\src\libraries\src.proj]
RegexCompiler.cs(62,9): Trim analysis warning IL2060: System.Text.RegularExpressions.RegexCompiler..cctor(): Call to `System.Reflection.MethodInfo.MakeGenericMethod(Type[])` can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [C:\git\runtime\src\libraries\src.proj]

In this case, the ILLinker should be able to discern that the methods being referenced don't have DynamicallyAccessedMembers attributes and it shouldn't cause a warning.

cc @vitek-karas @MichalStrehovsky @marek-safar

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions