I encountered the same error ("Failed to produce diagnostic for expression; please submit a bug report") and then discovered that is related to :
passing in a model object that is set with @State
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.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: