Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Missing warnings for compiler-generated code in types with RUC #2806

Closed

Description

@sbomer

The interaction between RUC-on-type and compiler-generated code gets a little subtle.

class Program
{
    static void Main() {
        // IL2026: Using member 'RUCType.RUCType()' ...
        // This should also warn about the state machine constructor.
        RequireAll(typeof(RUCType));
    }
    
    static void RequireAll([DAM(DAMT.All)] Type t) {}
}

[RequiresUnreferencedCode ("RUCType")]
class RUCType {
    public IEnumerable<int> M() {
        yield return 0;
    }
}

This isn't super high priority because there is an existing warning about the RUC type's constructor. Technically though, I think we should also warn about the state machine's constructor, since that could be accessed via reflection independently of the RUC type. We decided that RUC on type doesn't also apply to nested types, but I think it should for compiler-generated nested types, which are effectively a representation of the outer type's members.

Activity

  1. added this to the Future milestone on Jul 28, 2022
  2. self-assigned this
    on Jul 28, 2022
  3. sbomer commented on Jan 6, 2026

    @sbomer
    MemberAuthor

    Looking at this again, I don't think this is necessary because:

    • This will already warn for the reference to IEnumerable<int> M which conceptually is what represents the state machine ctor. The analyzer warning should be the same without having to understand what this compiles to.
    • Our intrinsic handling for GetNestedTypes doesn't seem to propagate the annotations anyway, so I don't think there's a way to reflect on the constructor without getting a warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    No status

Relationships

None yet

Development

No branches or pull requests

Issue actions