swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.6k stars 10.37k forks source link

Failed to produce diagnostic for expression #76763

Open Babojack opened 1 month ago

Babojack commented 1 month ago

Description

No response

Reproduction

@ViewBuilder private func lifeAreaView(for index: Int, isMiniFormat: Bool) -> some View { if index >= lifeAreas.count { Text("Life Area not found") .foregroundColor(.red) .background(Color.white) .cornerRadius(15) .shadow(radius: 5) .padding(10) } else { VStack(spacing: 15) { Text(lifeAreas[index].name) .font(.headline) .foregroundColor(.blue) .padding(.bottom, 5)

        if let image = lifeAreas[index].image {
            Image(uiImage: image)
                .resizable()
                .scaledToFill()
                .frame(width: isMiniFormat ? 70 : 100, height: isMiniFormat ? 70 : 100)
                .clipShape(Circle())
                .overlay(Circle().stroke(Color.gray, lineWidth: 1))
        } else {
            Circle()
                .fill(Color.gray.opacity(0.3))
                .frame(width: isMiniFormat ? 70 : 100, height: isMiniFormat ? 70 : 100)
                .overlay(Text("Photo").foregroundColor(.gray).font(.caption))
        }

        Slider(value: $lifeAreas[index].currentLevel, in: 0...1)
            .padding(.horizontal)

        HStack {
            Text(String(format: "%.0f%%", lifeAreas[index].currentLevel * 100))
                .font(.caption)
                .foregroundColor(.blue)

            Spacer()

            Button(action: {}) {
                Image(systemName: "note.text")
                    .foregroundColor(.blue)
            }

            Button(action: {
                withAnimation {
                    lifeAreas.remove(at: index)
                }
            }) {
                Image(systemName: "trash")
                    .foregroundColor(.red)
            }
        }
        .padding(.horizontal, 10)
    }
    .background(Color.white)
    .cornerRadius(15)
    .shadow(radius: 5)
    .padding(10)
}

}

Expected behavior

I expected the SwiftUI view to compile correctly and display each life area with its associated name, image, slider, and buttons. The @ViewBuilder should be able to handle conditional content rendering without throwing errors.

Environment

Swift 5.7.2 Xcode 14.5 (Build 14E350) macOS 13.0 Ventura

Additional information

This error consistently occurs when using @ViewBuilder with conditional content inside a VStack. Xcode returns the following error message: "Failed to produce diagnostic for expression; please submit a bug report." Related discussion: https://developer.apple.com/forums/thread/657391