Skip to content

Incorrect IL2026 for [RequiresUnreferencedCode] on type deriving from A<B> where B has new() in A<T> definition #108507

Closed

Description

@Sergio0694

Description

Spotted what seems to be an incorrect trim warning that's not suppressed correctly.

Reproduction Steps

[RequiresUnreferencedCode("")]
class A;

class B<T> where T : new();

[RequiresUnreferencedCode("")]
class C : B<A>;

Expected behavior

No warnings.

Actual behavior

image

Regression?

No, can repro on .NET 8 as well.

Activity

  1. dotnet-policy-service commented on Oct 3, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
    See info in area-owners.md if you want to be subscribed.

  2. added this to the 10.0.0 milestone on Oct 3, 2024
  3. sbomer commented on Oct 3, 2024

    @sbomer
    Member

    Related: #108523

    There are two problems here:

    • the warning isn't suppressed by RUC on C
    • the warning text mentions the wrong member (it should mention A's ctor, not C.
  4. removed
    untriagedNew issue has not been triaged by the area owner
    on Oct 3, 2024
  5. sbomer commented on Oct 3, 2024

    @sbomer
    Member

    An additional problem we might want to solve as part of this:

    class C : B<A>
    {
        public C()
        {
        }
    }

    In this case the analyzer misses the warning due to the implicit call to the base constructor. Note that the following example does produce a warning:

    [RequiresUnreferencedCode]
    class Requires {}
    
    class Derived : Requires
    {
        public Derived // warning IL2026
        {
        }
    }

    The logic for checking the new constraint should be moved into the analyzer's dataflow logic where the implicit base constructor call is visible.

  6. self-assigned this
    on Aug 15, 2025
  7. sbomer commented on Aug 15, 2025

    @sbomer
    Member

    the warning text mentions the wrong member (it should mention A's ctor, not C.

    This part was fixed in #108528.

    the warning isn't suppressed by RUC on C

    Note that this wouldn't be a problem if we fixed #118713. I'm still planning to fix this independently though.

  8. sbomer commented on Aug 18, 2025

    @sbomer
    Member

    An additional problem we might want to solve as part of this:

    I extracted this to a separate issue so the fix can focus on the customer-reported scenario.

  9. modified the milestones: 10.0.0, 11.0.0 on Aug 25, 2025
  10. added a commit that references this issue on Aug 14, 2026
    63666de
  11. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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