swiftlang / swift

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

"Failed to produce diagnostic for expression" in SwiftUI code #60793

Open Uncommon opened 2 years ago

Uncommon commented 2 years ago

Describe the bug "Failed to produce diagnostic for expression" error in the code below (line 31, the beginning of the body getter).

Steps To Reproduce Attempt to compile the code below. I had it in an Xcode playground as a simplified version of my original case.

Expected behavior The error should complain about the fact that FileChangeNode.children should be of type [FileChangeNode]? instead of [FileChange]?.

Environment (please fill out the following information)

import Foundation
import SwiftUI

enum DeltaStatus
{
  case unmodified, modified, added, deleted
}

struct FileChange: Equatable
{
  let path: String
  let status: DeltaStatus
}

struct FileChangeNode: Identifiable, Hashable
{
  let fileChange: FileChange
  let children: [FileChange]?

  var id: String { fileChange.path }

  func hash(into hasher: inout Hasher) { fileChange.path.hash(into: &hasher) }
}

struct FileTree: View
{
  let root: [FileChangeNode]

  var body: some View
  { // error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
    List(root, children: \.children) { _ in
      Text("hello")
    }
  }
}
xedin commented 2 years ago

This one is similar to https://github.com/apple/swift/issues/60779 but easier because all we need to do is to extend GenericArgumentsMismatchFailure to support KeyPathExpr anchored locators.

@angela-laar Something you might be interested in looking into.

Uncommon commented 2 years ago

Generic arguments mismatch... now I see my mistake :) I updated the expected behavior.