-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
The generated CustomEnumHelper for sequential enums uses array indexing in GetFormattedLength without validating the enum value:
public static int GetFormattedLength(CustomEnum value) => Lengths[(int)value];An out-of-range enum value will throw a raw IndexOutOfRangeException rather than a descriptive ArgumentOutOfRangeException.
In contrast, the switch-based helper generated for non-sequential enums throws a descriptive ArgumentOutOfRangeException for invalid values. The TryFormat method in the same sequential helper does include a bounds check ((uint)value >= Names.Length), so GetFormattedLength is inconsistent with its sibling.
Reproduction
Visible in the snapshot baseline:
SourceGeneratorSnapshotTests.BasicCompositePrimaryKey_SourceOutput#UnitTests.BasicPrimaryKey.g.verified.cs (lines ~266-274)
Expected behaviour
GetFormattedLength should validate the enum value and throw ArgumentOutOfRangeException for invalid values, consistent with the non-sequential enum helper and the TryFormat guard in the same class.
Discovered via
Snapshot testing added in #48 — this is a pre-existing generator issue, not a regression.