Closed moreindirection closed 4 months ago
Looks like this has been fixed on main recently:
error: value of optional type '[CatalogCategory]?' must be unwrapped to a value of type '[CatalogCategory]'
18 | else {
19 | List {
20 | ForEach(categories, id: \.categoryName) { category in
| |- error: value of optional type '[CatalogCategory]?' must be unwrapped to a value of type '[CatalogCategory]'
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
21 | Text(category.categoryName.capitalized)
22 | }
Please use a recent main branch snapshot from swift.org to verify and close.
Confirmed with a June 3 main as well. Let us close this on the spot.
As the OP, can confirm this is now fixed - thanks!
Description
While writing a SwiftUI view, I got the following compiler error:
I isolated the cause to the following short snippet. I eventually figured out that the problem is on line 21. Where the example code has:
it needs to handle the case where
categories
is nil. Replacing this line with the following fixes it:Note that if I remove the surrounding
Group
, I get the correct error:so the
Group
is necessary to reproduce the bug.Reproduction
Expected behavior
Instead of getting this message (which is raised at the surrounding
var body: some View
declaration), I should have received an error on theForEach
line, telling me that I was passing an optional to a method that expects a collection.As described above, without the surrounding
Group
, I get the correct error on the correct line.Environment
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0
Additional information
No response