"Failed to produce a diagnostic for expression; please file a bug report" error.

Why am I getting this error? There's another post similar to this, but it doesn't have any answers.
Code Block
import SwiftUI
struct ContentView: View {
    
    @State var clicked = 0
    
    var numberValue = [1: "won", 9: "Nein!", 69: "nice.", 123: "321", 666: "ILLUMINATI", 6969: "very nice."]
    
    func addOne() {
        clicked += 1
        print(clicked)
    }
    var body: some View {
        VStack{
            Text("Clicker: The Game")
                .font(.largeTitle)
                .fontWeight(.bold)
                .multilineTextAlignment(.center)
                .offset(y: -225)
            
            Text(numberValue[self.clicked] ?? String(self.clicked))
                .font(.system(size: 69))
                .offset(y: -125)
            
            Button(action: addOne) {
            Text("Tap me!")
                .offset(y: -10)
                .font(.system(size: 30))
                .background(RoundedRectangle(cornerRadius: CGFloat, style: RoundedCornerStyle = .circular))
                
        }
            
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Answered by OOPer in 632739022
The line 61 of your code has a severe syntax error.
Code Block
.background(RoundedRectangle(cornerRadius: CGFloat, style: RoundedCornerStyle = .circular))


It should be something like this:
Code Block
.background(RoundedRectangle(cornerRadius: 10, style: RoundedCornerStyle.circular))



Swift compiler should generate the right diagnostics pointing the line causing the issue. You should better send a bug report using the Feedback Assistant.
But, anyway, the current Swift compiler (you should better include the info of the Xcode version) is not good at generating proper diagnostics in ViewBuilder. You may need to comment-out/code-in each parts one by one and find which part of your code is causing this issue.
Accepted Answer
The line 61 of your code has a severe syntax error.
Code Block
.background(RoundedRectangle(cornerRadius: CGFloat, style: RoundedCornerStyle = .circular))


It should be something like this:
Code Block
.background(RoundedRectangle(cornerRadius: 10, style: RoundedCornerStyle.circular))



Swift compiler should generate the right diagnostics pointing the line causing the issue. You should better send a bug report using the Feedback Assistant.
But, anyway, the current Swift compiler (you should better include the info of the Xcode version) is not good at generating proper diagnostics in ViewBuilder. You may need to comment-out/code-in each parts one by one and find which part of your code is causing this issue.

I am also getting the same issue but have not been able to find a solution online or through GPT.

It is being flagged on line 7 in the below code "var body: some View {" Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project

Full code:

import SwiftUI

struct TermDetailView: View {
    let term: Term
    @EnvironmentObject var favouriteTermsData: FavouriteTermsData

    var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 16) {
                HStack {
                    Text(term.title)
                        .font(.largeTitle)
                        .fontWeight(.bold)

                    Spacer()

                    Button(action: {
                        favouriteTermsData.toggleFavourite(term.id)
                    }) {
                        Image(systemName: favouriteTermsData.isFavourite(term.id) ? "star.fill" : "star")
                            .font(.title2)
                            .foregroundColor(.yellow)
                    }
                }

                Text(term.definition)
                    .font(.body)

                if let example = term.example {
                    VStack(alignment: .leading, spacing: 12) {
                        Text("Example:")
                            .font(.title2)
                            .fontWeight(.bold)

                        Text(example)
                            .font(.body)
                    }
                }
            }
            .padding()
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

@bmoore you should start a new thread for this new question.

And provide some needed info, with definition of

  • Term
  • FavouriteTermsData

Apparently, problem comes from FavouriteTermsData, probably either toggleFavourite or isFavourite

In addition, you must set

            .environmentObject(favouriteTermsData)    

Where do you do it ?

I rebuilt an example based on your code:

struct Term {
    var id: UUID = UUID()
    var title: String = "title"
    var definition: String = "definition"
    var example: String = "example"
}

class FavouriteTermsData: ObservableObject {
    @Published var data: Bool = false
    
    func toggleFavourite(_ id: UUID) {
        self.data.toggle()
    }
    
    func isFavourite(_ id: UUID) -> Bool {
        self.data
    }
}

struct ContentView: View {  
    @StateObject var favouriteTermsData = FavouriteTermsData()
    
    var body: some View {
        TermDetailView()
            .environmentObject(favouriteTermsData)
    }
}

struct TermDetailView: View {
    let term: Term = Term()
    @EnvironmentObject var favouriteTermsData: FavouriteTermsData

    var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 16) {
                HStack {
                    Text(term.title)
                        .font(.largeTitle)
                        .fontWeight(.bold)

                    Spacer()

                    Button(action: {
                        favouriteTermsData.toggleFavourite(term.id)
                    }) {
                        Image(systemName: favouriteTermsData.isFavourite(term.id) ? "star.fill" : "star")
                            .font(.title2)
                            .foregroundColor(favouriteTermsData.isFavourite(term.id) ? .yellow : .green)
                    }
                }

                Text(term.definition)
                    .font(.body)

                if let example = term.example {
                    VStack(alignment: .leading, spacing: 12) {
                        Text("Example:")
                            .font(.title2)
                            .fontWeight(.bold)

                        Text(example)
                            .font(.body)
                    }
                }
            }
            .environmentObject(favouriteTermsData)      // ##
            .padding()
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

I encountered a "Type of expression is ambiguous without a type annotation" error when building a SwiftUI view with nested view hierarchies and complex conditional expressions. This error appears to be a compiler issue, as it occurs even when the code logic is sound and follows typical SwiftUI patterns. In some cases, the compiler fails to resolve types correctly, even with explicit type annotations.

var listView: some View { ScrollView { VStack(spacing: 10) { ForEach(filteredLists, id: .listId) { list in Button(action: { selectListAndNavigate(list) }) { GroceryListView( listName: list.listName, isHeartSelected: bindingForHeartSelected(at: viewModel.lists.firstIndex(where: { $0.listId == list.listId }) ?? 0), onCardTapped: { selectListAndNavigate(list) } ) .padding(.horizontal) } .buttonStyle(PlainButtonStyle()) }

            // NavigationLink outside ForEach to handle navigation
            NavigationLink(
                destination: ListView(
                    categories: viewModel.categorizedProducts,
                    listID: viewModel.currentList?.recordID,
                    listName: viewModel.listName,
                    createListViewModel: viewModel,
                    list: viewModel.currentList
                ),
                isActive: $isNavigatingToList
            ) {
                EmptyView() // Invisible trigger for navigation
            }
        }
    }
}
"Failed to produce a diagnostic for expression; please file a bug report" error.
 
 
Q