Diagnosing “Failed to produce diagnostic for expression; please submit a bug report”

Trying to use SwiftUI for a real-world project, I frequently run into this diagnostic from Xcode:

MyView.swift:18:5: Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project

The project is proprietary and so I've filed a bug report in Apple's bug reporter. But this comes up so often, and the only way I can figure it out is typically a series of code-commenting exercises to try to narrow it down.

Is there anything else I can do to help figure this out? In this particular case, it's a pretty simple bit of code (I just started working on this view). In fact, it's simple enough to include here:

    var
    body: some View
    {  <--- Failed to produce diagnostic for expression; please submit a bug report
		VStack
		{
			Text("\(self.products.count) products")
			LazyVStack
			{
				ForEach(self.products)
				{ inProduct in
	//				ProductItemCell(title: inProduct.name,
	//								state: .available,
	//								price: inProduct.price)
					Text("\(inProduct.name)")
				}
			}
		}
		.foregroundColor(.white)
    }

Any tips on how to ferret these out would be much appreciated. Thanks!

Update:

I replaced the ForEach with ForEach(self.products) {} and it gave me Cannot convert value of type '[Product]' to expected argument type 'Range<Int>', which was not expected, and Contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored, which was. Adding the suggested _ in (ForEach(self.products) { _ in } results in the "Failed to produce diagnostic for expression" error.

2 Likes

Oh hey! It's because I needed this:

extension Product : Identifiable {}

I tried all sorts of other things. ForEach(0..<3) works, but ForEach([1,2,3]) says Cannot convert value of type '[Int]' to expected argument type 'Range<Int>'.

Poor diagnostic generator needs love.

instead of making:

extension Product : Identifiable {}

you can:

ForEach(self.products, id: \.self)

Sure, but that doesn't really solve the diagnostic problem. If I forgot to conform to the protocol, I'm just as likely to forget to specify the ID.

1 Like
Terms of Service

Privacy Policy

Cookie Policy