mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
That is, if there's a problem with a witness, and the witness comes from a different extension from the conformance (or the original type, when the conformance is on an extension), put the main diagnostic on the conformance, with a note on the witness. This involves some shuffling and rephrasing of existing diagnostics too. There's a few reasons for this change: - More context. It may not be obvious why a declaration in file A.swift needs to be marked 'public' if you can't see the conformance in B.swift. - Better locations for imported declarations. If you're checking a conformance in a source file but the witness came from an imported module, it's better to put the diagnostic on the part you have control over. (This is especially true in Xcode, which can't display diagnostics on imported declarations in the source editor.) - Plays better with batch mode. Without this change, you can have diagnostics being reported in file A.swift that are tied to a conformance declared in file B.swift. Of course the contents of A.swift also affect the diagnostic, but compiling A.swift on its own wouldn't produce the diagnostic, and so putting it there is problematic. The change does in some cases make for a worse user experience, though; if you just want to apply the changes and move on, the main diagnostic isn't in the "right place". It's the note that has the info and possible fix-it. It's also a slightly more complicated implementation.
61 lines
2.0 KiB
Swift
61 lines
2.0 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
protocol P {
|
|
func foo(_ i: Int, x: Float) // expected-note 5 {{requirement 'foo(_:x:)' declared here}}
|
|
}
|
|
|
|
struct S1 : P {
|
|
func foo(_ i: Int, x: Float) { }
|
|
}
|
|
|
|
struct S2 : P {
|
|
func foo(_ i: Int, _ x: Float) { } // expected-error{{method 'foo' has different argument labels from those required by protocol 'P' ('foo(_:x:)')}}{{22-24=}}
|
|
}
|
|
|
|
struct S3 : P {
|
|
func foo(_ i: Int, y: Float) { } // expected-error{{method 'foo(_:y:)' has different argument labels from those required by protocol 'P' ('foo(_:x:)')}}{{22-22=x }}
|
|
}
|
|
|
|
struct S4 : P {
|
|
func foo(_ i: Int, _: Float) { } // expected-error{{method 'foo' has different argument labels from those required by protocol 'P' ('foo(_:x:)')}}{{22-22=x }}
|
|
}
|
|
|
|
struct S5 : P {
|
|
func foo(_ i: Int, z x: Float) { } // expected-error{{method 'foo(_:z:)' has different argument labels from those required by protocol 'P' ('foo(_:x:)')}}{{22-24=}}
|
|
}
|
|
|
|
struct S5a {
|
|
func foo(_ i: Int, z x: Float) { } // expected-note {{'foo(_:z:)' declared here}} {{none}}
|
|
}
|
|
extension S5a: P {} // expected-error{{method 'foo(_:z:)' has different argument labels from those required by protocol 'P' ('foo(_:x:)')}} {{none}}
|
|
|
|
struct Loadable { }
|
|
|
|
protocol LabeledRequirement {
|
|
func method(x: Loadable)
|
|
}
|
|
|
|
struct UnlabeledWitness : LabeledRequirement {
|
|
func method(x _: Loadable) {}
|
|
}
|
|
|
|
// rdar://problem/21333445
|
|
protocol P2 {
|
|
init(_ : Int) // expected-note{{requirement 'init' declared here}}
|
|
}
|
|
|
|
struct XP2 : P2 { // expected-error{{initializer 'init(foo:)' has different argument labels from those required by protocol 'P2' ('init')}}
|
|
let foo: Int
|
|
}
|
|
|
|
// rdar://problem/22981205
|
|
protocol P3 {
|
|
subscript(val: String, label arg: String) -> Int { get } // expected-note{{requirement 'subscript(_:label:)' declared here}}
|
|
}
|
|
|
|
class MislabeledSubscript : P3 {
|
|
subscript(val: String, label: String) -> Int { // expected-error{{method 'subscript' has different argument labels from those required by protocol 'P3' ('subscript(_:label:)')}}
|
|
return 1
|
|
}
|
|
}
|