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

why am i getting this error?????

struct ContentView: View { @StateObject private var dreamViewModel = DreamViewModel() @State private var showDreamEntry = false @State private var showDreamLog = false @State private var showDreamAnalysis = false @State private var dreamText: String = ""

var body: some View { // Error here.
    NavigationView {
        VStack {
            navigationLinks
            
            Button(action: {
                showDreamAnalysis = true
            }) {
                Text("Analyze Dream")
            }
        }
        .fullScreenCover(isPresented: $showDreamAnalysis) {
            DreamAnalysisView(dreamText: $dreamText, selectedDream: dreamText != "" ? $dreamText : nil)
        }
    }
}

private var navigationLinks: some View {
    VStack {
        NavigationLink(destination: DreamEntryView(dreamViewModel: dreamViewModel), isActive: $showDreamEntry) {
            EmptyView()
        }
        NavigationLink(destination: DreamLogView(savedDreams: dreamViewModel.savedDreams), isActive: $showDreamLog) {
            EmptyView()
        }
        
        Button(action: {
            showDreamEntry = true
        }) {
            Text("Go to Dream Entry")
        }
        
        Button(action: {
            showDreamLog = true
        }) {
            Text("Go to Dream Log")
        }
    }
}

}

struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

Post not yet marked as solved Up vote post of big_ev Down vote post of big_ev
678 views

Replies

It is a very generic error. Possible cause would be a mistake in a parameter list. Missing parameter, wrong order, mispelling…

You should check in particular

                DreamAnalysisView(dreamText: $dreamText, selectedDream: dreamText != "" ? $dreamText : nil)

Add parenthesis

                DreamAnalysisView(dreamText: $dreamText, selectedDream: (dreamText != "" ? $dreamText  : nil) )

And please show the definition of DreamAnalysisView.

What Claude31 said but also…

It’d be great if you could file a bug and attach a project that reproduces this. The fact that you’re seeing this diagnostic clearly indicates that the compiler has failed in some way.

If you do file a bug, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I encountered the same error ("Failed to produce diagnostic for expression; please submit a bug report") and then discovered that is related to :

  1. passing in a model object that is set with @State
  2. the preview code that most likely causes the problem.

Here's a simplified example of what I had that caused the problem.

struct ParentView: View {
    @State var userTaskItem: UserTask?  // this is my Model I pass into the ChildView

    var body: some View {
        Form{
        }.sheet(isPresented: $isUserTaskViewShown, onDismiss: didDismiss,
               content: {
                    ChildView(userTask: $userTaskItem) // passing in bound Model item to child view
             })
}

struct ChildView: View {
    @Binding var userTask : UserTask?  // Model is bound to parent
    var body: some View {
        Group{ 
         }
 }   

#Preview {
   // had something like this and I got extremely strange errors.
     var userTask: UserTask? = UserTask()
    ChildView(userTask: PreviewHelper.$userTask)
}

My point is that you need to look closely at your bindings on Models and what your preview is doing.