Open
Description
Description
When you have (1) a key path to a value of type A, passed to (2) a struct initializer with two overloads which expect the key path to be either of type B or C, (3) inside of a result builder, Swift reports “failed to produce diagnostic for expression; please submit a bug report” instead of a useful error.
Steps to reproduce
struct Model {
let member = ""
}
struct Wrapper {
// produces correct error message if one of these is removed
init(keyPath: KeyPath<Model, Int32>) {}
init(keyPath: KeyPath<Model, Float>) {}
}
// can be any result builder
@resultBuilder struct MyResultBuilder {
static func buildBlock(_ components: Void...) -> Void {}
}
// 🛑 Type of expression is ambiguous without more context
let baz = Wrapper(keyPath: \.member)
@MyResultBuilder
// 🛑 Failed to produce diagnostic for expression
var built: Void {
let baz = Wrapper(keyPath: \.member)
}
Expected behavior
error: TypeConfusion.playground:18:15: error: no exact matches in call to initializer
let baz = Wrapper(keyPath: \.member)
^
TypeConfusion.playground:7:5: note: candidate expects value of type 'KeyPath<Model, Int32>' for parameter #1 (got 'KeyPath<Model, String>')
init(keyPath: KeyPath<Model, Int32>) {}
^
TypeConfusion.playground:8:5: note: candidate expects value of type 'KeyPath<Model, Float>' for parameter #1 (got 'KeyPath<Model, String>')
init(keyPath: KeyPath<Model, Float>) {}
Environment
- Both the integrated Swift toolchain and Swift Development Snapshot 2023-04-25 (a)
- Xcode 14.3, Build version 14E222b
- Deployment target: macOS 13.3
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.Feature: closuresThe Swift compiler itselfFeature: declarationsBug: Diagnostics Quality of ImplementationFeature: expressionsBug → internal error: Failed to produce diagnostic for expressionFeature → declarations: FunctionsFeature: key paths (both native and Objective-C)Feature: Overloading symbol namesFeature: Result buildersArea → compiler: Semantic analysis