Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inconsistent warning code for array parameter passed to annotated location in ILLink/analyzer #96646

@sbomer

Description

@sbomer
static void Method(Type[] interfaces) {
    foreach (Type i in interfaces)
        i.GetMethods(); // warning here. IL2075 for analyzer, IL2065 for ILLink
}

The ILLink Roslyn analyzer produces IL2075 (unannotated method return value flows to 'this' parameter with requirements), because it sees the return value of Current.get used as the receiver for GetMethods.

ILLink produces IL2065 ('this' parameter cannot be statically determined), because when it sees ldelem.ref of the array method parameter, it turns this into an "unknown" value, which has a different warning code.

Fundamentally this is due to the analyzer seeing a different lowering of the foreach loop than illink. Fixing this seems tricky.

Found while investigating #96462. There's an existing testcase similar to this:

[ExpectedWarning ("IL2063", ProducedBy = Tool.Trimmer)] // The types loaded from the array don't have annotations, so the "return" should warn
[ExpectedWarning ("IL2073", ProducedBy = Tool.Analyzer)] // Analyzer tracks resultType as the value from IEnumerable.Current.get()
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public static Type TestBackwardEdgeWithLdElem (Type[] types = null)
{
Type resultType = null;
foreach (var type in types) {
resultType = type;
}
return resultType;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzers

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions