Skip to content

Avoid force-casting allCases in HPicker and VPicker - #10

Merged
Jeehut merged 1 commit into
mainfrom
wip/picker-allcases
Oct 15, 2026
Merged

Jeehut merged 1 commit into
mainfrom
wip/picker-allcases

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 14, 2026

Copy link
Copy Markdown
Member

Overview

The CaseIterable initializers of HPicker and VPicker force-cast T.allCases as! [T], which crashes for types whose AllCases is not an Array (for example a custom allCases returning a ContiguousArray). They now use Array(T.allCases), which is identical for the usual Array case.

Split out of #7.

How this was verified

PickerTests builds both pickers for an enum whose AllCases is a ContiguousArray.

Red, with main's HPicker.swift/VPicker.swift (the old code crashes the test process):

Could not cast value of type 'Swift.ContiguousArray<…Fruit>' to 'Swift.Array<…Fruit>'
error: … exited with unexpected signal code 6

Green, this branch:

✔ Test run with 2 tests in 1 suite passed.

No behavior change for apps: FocusBeats and CrossCraft use the pickers only with plain enums, whose AllCases is an Array.

CaseIterable only requires AllCases to be a Collection, so a type with
a non-Array AllCases crashed the CaseIterable initializers with a
failed `as! [T]` cast. Array(T.allCases) works for every collection.
@Jeehut
Jeehut merged commit 343a732 into main Oct 15, 2026
5 checks passed
@Jeehut
Jeehut deleted the wip/picker-allcases branch October 15, 2026 08:50
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.

1 participant