You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Music factories accept undefined enum values: Pitch.Create(NoteLetter.C, (Accidental)7, 4) returns G4, and Section.Create((SectionType)42, …).ToString() can't be parsed back #533
The type-safe factories from the music type-safe-factories plan take enums, but they never check that the value is defined:
Semantics.Music/Pitch.cs:~45-56: Create passes (int)letter and (int)accidental straight into MidiOf (:~108). The only check is the 0..127 MIDI range.
Semantics.Music/PitchClass.cs:~31: same pattern.
Semantics.Music/Section.cs:~36-40: Create stores any SectionType.
ChordSymbolWriter.HasSupportedValues (ChordSymbolWriter.cs:~113-118) already guards chord enums with Enum.IsDefined, so this check is a known pattern in the codebase.
Failure scenarios
Pitch.Create((NoteLetter)1, Accidental.Natural, 4) returns C#4, and Pitch.Create(NoteLetter.C, (Accidental)7, 4) returns G4. Neither throws. A value coming from deserialised or user-supplied ints silently becomes a different note.
Section.Create((SectionType)42, prog).ToString() writes [42]\n4/4 C G, and Section.TryParse rejects that text because TryParseSectionType refuses digits (Section.cs:~283-299). That breaks the plan's Parse(x.ToString()) == x round-trip guarantee.
Suggested fix / acceptance criteria
Pitch.Create, PitchClass creation and Section.Create throw ArgumentOutOfRangeException naming the parameter when NoteLetter, Accidental or SectionType is not a defined value.
Tests cover each undefined-value case, plus the round trip for every defined SectionType.
Priority: Medium. It only happens with out-of-range enum casts (deserialised or user-supplied ints). When it does, it silently produces the wrong note and breaks the Parse(x.ToString()) == x guarantee.
Area / suggested assignee:Semantics.Music (Pitch, PitchClass, Section). Maintainer: matt-edmondson.
Activity
matt-edmondson commentedon Nov 1, 2026
Triage
Parse(x.ToString()) == xguarantee.Semantics.Music(Pitch,PitchClass,Section). Maintainer:matt-edmondson.Section.Parseaccepts numbers and comma lists as section types ([Verse, Chorus]parses as Chorus,[42]as undefined 42) #318 / PR [patch] Accept only one declared SectionType name in a section header #411 (Section.Parserejecting numeric section types), which is why[42]no longer round-trips.Enum.IsDefinedpattern already inChordSymbolWriter.HasSupportedValues.Generated by Claude Code