Skip to content

Add #[flags] attribute support to windows-rdl for System.FlagsAttribute - #3965

Merged
Kenny Kerr (kennykerr) merged 2 commits into
masterfrom
copilot/add-flags-attribute-handling
Mar 10, 2026
Merged

Add #[flags] attribute support to windows-rdl for System.FlagsAttribute#3965
Kenny Kerr (kennykerr) merged 2 commits into
masterfrom
copilot/add-flags-attribute-handling

Conversation

Copilot AI commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

System.FlagsAttribute is a CLS-defined attribute that won't appear in RDL definitions, but is encoded in ECMA-335 metadata like any other custom attribute. The RDL reader and writer had no awareness of it.

Reader (RDL → .winmd)

  • #[flags] on an enum is now a built-in RDL keyword (like repr): skipped by the generic attribute resolver and encoded directly as a System.FlagsAttribute custom attribute on the enum's TypeDef
  • Validates that #[flags] takes no arguments

Writer (.winmd → RDL)

  • Detects System.FlagsAttribute (by namespace + name) on enums and emits #[flags] in the RDL output after #[repr(...)]
  • Filters FlagsAttribute from the generic attribute pass to prevent incorrect emission as #[System::Flags]

Tests

  • Roundtrip test (enum-flags.rdl / enum-flags.rs) using the VirtualKeyModifiers example from the issue
  • Inline error test for #[flags(args)] (flags takes no arguments)
#[repr(u32)]
#[flags]
enum VirtualKeyModifiers {
    None = 0,
    Control = 1,
    Menu = 2,
    Shift = 4,
    Windows = 8,
}
Original prompt

This section details on the original issue you should resolve

<issue_title>windows-rdl doesn't handle System.Flags</issue_title>
<issue_description>Some enums may have the System.FlagsAttribute but since this attribute is defined by ECMA-335 and CLS its definition won't appear in RDL and should be handled like the existing special RDL attributes like repr. It does however get encoded in the Attribute table like other attributes but should be known to windows-rdl just like other well known types defined in the System namespace.

I think what we need is the ability to write an enum with an optional flags attribute like this:

#[repr(u32)]
#[flags]
enum VirtualKeyModifiers {
    None = 0,
    Control = 1,
    Menu = 2,
    Shift = 4,
    Windows = 8,
}

The flags attribute accepts no arguments and is encoded as a System.FlagsAttribute in ECMA-335. Conversely, the Writer should look for the System.FlagsAttribute attribute on enums and emit it as the .rdl #[flags] attribute but only on enums. This should match Windows APIs like Windows.System.VirtualKeyModifiers.</issue_description>

Comments on the Issue (you are Copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Copilot AI changed the title [WIP] Add handling for System.Flags in windows-rdl Add #[flags] attribute support to windows-rdl for System.FlagsAttribute Mar 10, 2026
@kennykerr
Kenny Kerr (kennykerr) marked this pull request as ready for review March 10, 2026 15:26
@kennykerr
Kenny Kerr (kennykerr) merged commit 71a71bd into master Mar 10, 2026
39 checks passed
@kennykerr
Kenny Kerr (kennykerr) deleted the copilot/add-flags-attribute-handling branch March 10, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows-rdl doesn't handle System.Flags

2 participants