swiftlang / swift

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

Failed to produce diagnostic for expression #72888

Open God2525 opened 3 months ago

God2525 commented 3 months ago

Description

Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)

When I ran the code, I got this error on line 4 of NavigationExperiment.

Reproduction

NavigationExperiment

import SwiftUI

struct NavigationExperiment: View {
    var body: some View {
        VStack {
            NavigationStack { 
                NavigationLink("Push Me!") { 
                    MyApp()
                }
                    //#-learning-code-snippet(addSecondNavLink)

            }
        }

    }
}

MyApp

import SwiftUI
import Guide
//#-learning-code-snippet(myApp)

@main
/*#-code-walkthrough(myApp.appProtocol)*/
struct MyApp: App {
    /*#-code-walkthrough(myApp.appProtocol)*/
    //#-learning-code-snippet(createInstanceCreatureZoo)

    /*#-code-walkthrough(myApp.body)*/
    var body: some Scene {
        SPCAssessableWindowGroup(app: self, assessmentCandidates: [CreatureZoo()]) {
            //#-learning-code-snippet(addNavView)

            /*#-code-walkthrough(myApp.contentView)*/
            Bindings()
        }
    }
    /*#-code-walkthrough(myApp.body)*/
}

Bindings

import SwiftUI
//#-learning-code-snippet(toggleExperiment)

struct Bindings: View {
    /*#-code-walkthrough(toggle.stateVar)*/
    @State var isOn = false
    @State var color = Color.primary
    /*#-code-walkthrough(toggle.stateVar)*/
    //#-learning-code-snippet(addAStateVar)

    var body: some View {
        VStack {
            /*#-code-walkthrough(toggle.viewDef)*/
            Toggle("Press Me", isOn: /*#-code-walkthrough(toggle.binding)*/ $isOn /*#-code-walkthrough(toggle.binding)*/)
            /*#-code-walkthrough(toggle.viewDef)*/

            ColorPicker("Pick a color", selection: $color)

            Image(systemName: isOn ? "battery.100" : "battery.25")
                .font(.system(size: 150))
                .foregroundColor(color)
            //#-learning-code-snippet(addAColorModifier)
            Text("whatz up")
                .foregroundColor(color)
            //#-learning-code-snippet(addATextView)

        }
        .padding()
    }
}

struct Bindings_Previews: PreviewProvider {
    static var previews: some View {
        Bindings().assess()
    }
}

Expected behavior

I expected that when you clicked the button "Push me!" to redirect to the MyApp page. However, when I tried to run it, it said it was unable to produce a diagnostic.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0

I was using Swift Playgrounds, "Keep Going with Apps"

Additional information

No response

xedin commented 3 months ago

@God2525 could you please check whether this is fixed in the latest thunk development toolchain from swift.org?