Skip to content

ILC considers types as constructed for IsAssignableFrom #116032

Open
@sbomer

Description

@sbomer

Not sure if this is by design, but it leads to a strange user experience. Repro:

using System.Diagnostics.CodeAnalysis;

typeof(C).IsAssignableFrom(typeof(int));
Helper(null);

static void Helper(I i) => i.Foo();

interface I {
    void Foo();
}

// Uncomment this and there are no warnings
// [RequiresUnreferencedCode("")]
class C : I {
    public void Foo() => RUC(); // Warns with PublishAot

    [RequiresUnreferencedCode("")]
    static void RUC() { }
}

This gives a false positive warning at the call to RUC even though C is never constructed. ILLink doesn't produce this warning. Uncommenting RequiresUnreferencedCode on the class gets rid of the warning, so it looks like we already (correctly) don't consider the reference to C to be a call to the constructor, at least for the purpose of producing analysis warnings.

This causes some warnings in azure-mcp: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/e946c1a24dff26f201ecadde303a66cf5df3af0a/Microsoft.Azure.Cosmos/src/direct/PathsHelper.cs#L767.

@MichalStrehovsky @agocke

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions