Skip to content

ILLink: extra warning for generic parameter with new constraint and annotation #119290

@sbomer

Description

@sbomer

Repro:

// IL2026 for type (ILLink produces this twice)
class ClassWithWarningOnGenericArgumentConstructor_NewAndAnnotation : RequiresNewAndConstructors<ClassWithRequires>
{
    // IL2026 (ILLink produces this twice)
    public ClassWithWarningOnGenericArgumentConstructor_NewAndAnnotation()
    {
    }
}

class RequiresNewAndConstructors<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T> where T : new();

[RequiresUnreferencedCode("Message for --ClassWithRequires--")]
class ClassWithRequires;

This produces a warning on the type and on the implicit call to the base constructor (ILLink and ILC both do this). But ILLink produces two of each. That's because:

  • ILC handles the new constraint by treating it like PublicParameterlessConstructor annotations
  • ILLink handles the new constraint separately, while marking generic argument types

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions