Skip to content

Commit baa20ae

Browse files
authored
Merge pull request #67909 from nishithshah2211/imperative-fixits
[Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
2 parents 4ba0173 + 8e2e625 commit baa20ae

File tree

77 files changed

+312
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+312
-313
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,9 +2694,9 @@ NOTE(inherited_protocol_does_not_conform,none,
26942694
NOTE(no_witnesses,none,
26952695
"protocol requires "
26962696
"%select{initializer %1|function %1|property %1|subscript}0 with type %2"
2697-
"%select{|; do you want to add a stub?}3",
2697+
"%select{|; add a stub for conformance}3",
26982698
(RequirementKind, const ValueDecl *, Type, bool))
2699-
NOTE(missing_witnesses_general,none, "do you want to add protocol stubs?",
2699+
NOTE(missing_witnesses_general,none, "add stubs for conformance",
27002700
())
27012701
NOTE(ambiguous_witnesses,none,
27022702
"multiple matching "
@@ -2709,7 +2709,7 @@ NOTE(ambiguous_witnesses_wrong_name,none,
27092709
"subscript operators}0 with type %2",
27102710
(RequirementKind, const ValueDecl *, Type))
27112711
NOTE(no_witnesses_type,none,
2712-
"protocol requires nested type %0; do you want to add it?",
2712+
"protocol requires nested type %0; add nested type %0 for conformance",
27132713
(const AssociatedTypeDecl *))
27142714
NOTE(default_associated_type_req_fail,none,
27152715
"default type %0 for associated type %1 (from protocol %2) "
@@ -6657,16 +6657,15 @@ WARNING(debug_long_expression, none,
66576657

66586658
ERROR(empty_switch_stmt,none,
66596659
"'switch' statement body must have at least one 'case' or 'default' "
6660-
"block; do you want to add a default case?",())
6660+
"block; add a default case",())
66616661
ERROR(non_exhaustive_switch,none, "switch must be exhaustive", ())
66626662
ERROR(possibly_non_exhaustive_switch,none,
66636663
"the compiler is unable to check that this switch is exhaustive in reasonable time",
66646664
())
66656665

66666666
NOTE(missing_several_cases,none,
6667-
"do you want to add "
6668-
"%select{missing cases|a default clause}0"
6669-
"?", (bool))
6667+
"add "
6668+
"%select{missing cases|a default clause}0", (bool))
66706669
NOTE(missing_unknown_case,none,
66716670
"handle unknown values using \"@unknown default\"", ())
66726671

test/AutoDiff/Sema/DerivedConformances/derived_differentiable_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import _Differentiation
44

55
protocol TangentVectorP: Differentiable {
6-
// expected-note @+1 {{protocol requires property 'requirement' with type 'Int'; do you want to add a stub?}}
6+
// expected-note @+1 {{protocol requires property 'requirement' with type 'Int'; add a stub for conformance}}
77
var requirement: Int { get }
88
}
99

test/AutoDiff/Sema/differentiable_attr_type_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public protocol DoubleDifferentiableDistribution: DifferentiableDistribution
557557

558558
public protocol HasRequirement {
559559
@differentiable(reverse)
560-
// expected-note @+1 {{protocol requires function 'requirement' with type '<T> (T, T) -> T'; do you want to add a stub?}}
560+
// expected-note @+1 {{protocol requires function 'requirement' with type '<T> (T, T) -> T'; add a stub for conformance}}
561561
func requirement<T: Differentiable>(_ x: T, _ y: T) -> T
562562
}
563563

test/ClangImporter/enum-new.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ func test() {
1313
case .Yellow, .Magenta, .Black, .Cyan: break
1414
}
1515

16-
switch getColorOptions() { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
16+
switch getColorOptions() { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
1717
case ColorOptions.Pastel: break
1818
case ColorOptions.Swift: break
1919
}
2020

21-
switch 5 as Int16 { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; do you want to add a default case?}}
21+
switch 5 as Int16 { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}
2222
}
2323
}

test/Compatibility/special_func_name.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -swift-version 4
22

33
protocol P1 {
4-
static func `init`(_: Int) // expected-note {{protocol requires function 'init' with type '(Int) -> ()'; do you want to add a stub?}}
4+
static func `init`(_: Int) // expected-note {{protocol requires function 'init' with type '(Int) -> ()'; add a stub for conformance}}
55
// expected-note@-1 {{did you mean 'init'?}}
66
}
77

@@ -14,7 +14,7 @@ struct S12 : P1 { // expected-error {{type 'S12' does not conform to protocol 'P
1414
}
1515

1616
protocol P2 {
17-
init(_: Int) // expected-note {{protocol requires initializer 'init(_:)' with type 'Int'; do you want to add a stub?}}
17+
init(_: Int) // expected-note {{protocol requires initializer 'init(_:)' with type 'Int'; add a stub for conformance}}
1818
}
1919

2020
struct S21 : P2 { // expected-error {{type 'S21' does not conform to protocol 'P2'}}

test/Concurrency/async_conformance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import Foundation
66

77
// async objc requirement, sync witness
88
@objc protocol Tracker {
9-
func track(event: String) async // expected-note {{protocol requires function 'track(event:)' with type '(String) async -> ()'; do you want to add a stub?}}
9+
func track(event: String) async // expected-note {{protocol requires function 'track(event:)' with type '(String) async -> ()'; add a stub for conformance}}
1010
}
1111
class Dog: NSObject, Tracker { // expected-error {{type 'Dog' does not conform to protocol 'Tracker'}}
1212
func track(event: String) {} // expected-note {{candidate is not 'async', but @objc protocol requirement is}}
1313
}
1414

1515
// sync objc requirement, async witness
1616
@objc protocol Runner {
17-
func run(event: String) // expected-note {{protocol requires function 'run(event:)' with type '(String) -> ()'; do you want to add a stub?}}
17+
func run(event: String) // expected-note {{protocol requires function 'run(event:)' with type '(String) -> ()'; add a stub for conformance}}
1818
}
1919
class Athlete: NSObject, Runner { // expected-error {{type 'Athlete' does not conform to protocol 'Runner'}}
2020
func run(event: String) async {} // expected-note {{candidate is 'async', but @objc protocol requirement is not}}
@@ -33,7 +33,7 @@ class Foodie: Snacker {
3333

3434
// sync swift protocol, async witness
3535
protocol Backer {
36-
func back(stonk: String) // expected-note {{protocol requires function 'back(stonk:)' with type '(String) -> ()'; do you want to add a stub?}}
36+
func back(stonk: String) // expected-note {{protocol requires function 'back(stonk:)' with type '(String) -> ()'; add a stub for conformance}}
3737
}
3838

3939
class Investor: Backer { // expected-error {{type 'Investor' does not conform to protocol 'Backer'}}

test/Concurrency/async_initializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct Location {
148148
}
149149

150150
protocol DefaultConstructable {
151-
init() // expected-note {{protocol requires initializer 'init()' with type '()'; do you want to add a stub?}} {{+2:43-43=\n init() {\n <#code#>\n \}\n}}
151+
init() // expected-note {{protocol requires initializer 'init()' with type '()'; add a stub for conformance}} {{+2:43-43=\n init() {\n <#code#>\n \}\n}}
152152
}
153153
extension Location: DefaultConstructable {} // expected-error {{type 'Location' does not conform to protocol 'DefaultConstructable'}}
154154

test/Constraints/associated_types.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protocol XReqt {}
6262
protocol YReqt {}
6363

6464
protocol SameTypedDefaultWithReqts {
65-
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; do you want to add it?}}
66-
associatedtype Y: YReqt // expected-note{{protocol requires nested type 'Y'; do you want to add it?}}
65+
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; add nested type 'X' for conformance}}
66+
associatedtype Y: YReqt // expected-note{{protocol requires nested type 'Y'; add nested type 'Y' for conformance}}
6767
static var x: X { get }
6868
static var y: Y { get }
6969
}
@@ -86,7 +86,7 @@ struct UsesSameTypedDefaultWithoutSatisfyingReqts: SameTypedDefaultWithReqts {
8686
}
8787

8888
protocol SameTypedDefaultBaseWithReqts {
89-
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; do you want to add it?}}
89+
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; add nested type 'X' for conformance}}
9090
static var x: X { get }
9191
}
9292
protocol SameTypedDefaultDerivedWithReqts: SameTypedDefaultBaseWithReqts {

test/Constraints/issue-52995.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// https://github.com/apple/swift/issues/52995
44

55
protocol Nested {
6-
associatedtype U // expected-note {{protocol requires nested type 'U'; do you want to add it?}}
6+
associatedtype U // expected-note {{protocol requires nested type 'U'; add nested type 'U' for conformance}}
77
}
88

99
class A<M> {

test/Constraints/issue-54820.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
protocol Protocol {
66
associatedtype Index: Comparable
77
subscript(bounds: Range<Index>) -> Int { get }
8-
// expected-note@+1 {{protocol requires subscript with type '(Wrapper<Base>.Index) -> Int' (aka '(Base.Index) -> Int'); do you want to add a stub?}}
8+
// expected-note@+1 {{protocol requires subscript with type '(Wrapper<Base>.Index) -> Int' (aka '(Base.Index) -> Int'); add a stub for conformance}}
99
subscript(position: Index) -> Int { get }
1010
}
1111

0 commit comments

Comments
 (0)