Skip to content

[Diagnostics] Use imperative msg for protocol conformance & switch-case fixits #67909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2689,9 +2689,9 @@ NOTE(inherited_protocol_does_not_conform,none,
NOTE(no_witnesses,none,
"protocol requires "
"%select{initializer %1|function %1|property %1|subscript}0 with type %2"
"%select{|; do you want to add a stub?}3",
"%select{|; add a stub for conformance}3",
(RequirementKind, const ValueDecl *, Type, bool))
NOTE(missing_witnesses_general,none, "do you want to add protocol stubs?",
NOTE(missing_witnesses_general,none, "add stubs for conformance",
())
NOTE(ambiguous_witnesses,none,
"multiple matching "
Expand All @@ -2704,7 +2704,7 @@ NOTE(ambiguous_witnesses_wrong_name,none,
"subscript operators}0 with type %2",
(RequirementKind, const ValueDecl *, Type))
NOTE(no_witnesses_type,none,
"protocol requires nested type %0; do you want to add it?",
"protocol requires nested type %0; add nested type %0 for conformance",
(const AssociatedTypeDecl *))
NOTE(default_associated_type_req_fail,none,
"default type %0 for associated type %1 (from protocol %2) "
Expand Down Expand Up @@ -6643,16 +6643,15 @@ WARNING(debug_long_expression, none,

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

NOTE(missing_several_cases,none,
"do you want to add "
"%select{missing cases|a default clause}0"
"?", (bool))
"add "
"%select{missing cases|a default clause}0", (bool))
NOTE(missing_unknown_case,none,
"handle unknown values using \"@unknown default\"", ())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import _Differentiation

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

Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/Sema/differentiable_attr_type_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public protocol DoubleDifferentiableDistribution: DifferentiableDistribution

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

Expand Down
4 changes: 2 additions & 2 deletions test/ClangImporter/enum-new.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ func test() {
case .Yellow, .Magenta, .Black, .Cyan: break
}

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

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?}}
switch 5 as Int16 { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}
}
}
4 changes: 2 additions & 2 deletions test/Compatibility/special_func_name.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift -swift-version 4

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

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

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

struct S21 : P2 { // expected-error {{type 'S21' does not conform to protocol 'P2'}}
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/async_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import Foundation

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

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

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

class Investor: Backer { // expected-error {{type 'Investor' does not conform to protocol 'Backer'}}
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/async_initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct Location {
}

protocol DefaultConstructable {
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}}
init() // expected-note {{protocol requires initializer 'init()' with type '()'; add a stub for conformance}} {{+2:43-43=\n init() {\n <#code#>\n \}\n}}
}
extension Location: DefaultConstructable {} // expected-error {{type 'Location' does not conform to protocol 'DefaultConstructable'}}

Expand Down
6 changes: 3 additions & 3 deletions test/Constraints/associated_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protocol XReqt {}
protocol YReqt {}

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

protocol SameTypedDefaultBaseWithReqts {
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; do you want to add it?}}
associatedtype X: XReqt // expected-note{{protocol requires nested type 'X'; add nested type 'X' for conformance}}
static var x: X { get }
}
protocol SameTypedDefaultDerivedWithReqts: SameTypedDefaultBaseWithReqts {
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/issue-52995.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// https://github.com/apple/swift/issues/52995

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

class A<M> {
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/issue-54820.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
protocol Protocol {
associatedtype Index: Comparable
subscript(bounds: Range<Index>) -> Int { get }
// expected-note@+1 {{protocol requires subscript with type '(Wrapper<Base>.Index) -> Int' (aka '(Base.Index) -> Int'); do you want to add a stub?}}
// expected-note@+1 {{protocol requires subscript with type '(Wrapper<Base>.Index) -> Int' (aka '(Base.Index) -> Int'); add a stub for conformance}}
subscript(position: Index) -> Int { get }
}

Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/moveonly_constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func copyableExistentials(_ a: Any, _ e1: Error, _ e2: any Error, _ ah: AnyHasha
// ensure that associated types can't be witnessed by move-only types

protocol HasType<Ty> {
associatedtype Ty // expected-note 3{{protocol requires nested type 'Ty'; do you want to add it?}}
associatedtype Ty // expected-note 3{{protocol requires nested type 'Ty'; add nested type 'Ty' for conformance}}
}

class SomeGuy: HasType { // expected-error {{type 'SomeGuy' does not conform to protocol 'HasType'}}
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/result_builder_diags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ struct MyView {
}

@TupleBuilder var emptySwitch: some P {
switch Optional.some(1) { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; do you want to add a default case?}}
switch Optional.some(1) { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/same_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s

protocol Fooable {
associatedtype Foo // expected-note{{protocol requires nested type 'Foo'; do you want to add it?}}
associatedtype Foo // expected-note{{protocol requires nested type 'Foo'; add nested type 'Foo' for conformance}}

var foo: Foo { get }
}
Expand Down
4 changes: 2 additions & 2 deletions test/Generics/associated_type_where_clause.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ConcreteConforms2: Conforms { typealias T = Int }
struct ConcreteConformsNonFoo2: Conforms { typealias T = Float }

protocol NestedConforms {
associatedtype U where U: Conforms, U.T: Foo2 // expected-note{{protocol requires nested type 'U'; do you want to add it?}}
associatedtype U where U: Conforms, U.T: Foo2 // expected-note{{protocol requires nested type 'U'; add nested type 'U' for conformance}}

func foo(_: U)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func needsNestedConformsDefault<X: NestedConformsDefault>(_: X.Type) {
}

protocol NestedSameType {
associatedtype U: Conforms where U.T == Int // expected-note{{protocol requires nested type 'U'; do you want to add it?}}
associatedtype U: Conforms where U.T == Int // expected-note{{protocol requires nested type 'U'; add nested type 'U' for conformance}}

func foo(_: U)
}
Expand Down
2 changes: 1 addition & 1 deletion test/Generics/constrained_type_witnesses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

protocol P {
associatedtype A
// expected-note@-1 5{{protocol requires nested type 'A'; do you want to add it?}}
// expected-note@-1 5{{protocol requires nested type 'A'; add nested type 'A' for conformance}}
}

struct S1<T> {}
Expand Down
2 changes: 1 addition & 1 deletion test/Parse/ConditionalCompilation/switch_case.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func foo(x: E, intVal: Int) {
}

// Empty check.
switch intVal { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; do you want to add a default case?}}
switch intVal { // expected-error {{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}
#if NEVER
case 1:
break
Expand Down
2 changes: 1 addition & 1 deletion test/Parse/matching_patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ case _: // expected-warning {{case is already handled by previous patterns; cons

var e : Any = 0

switch e { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch e { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
// 'is' pattern.
case is Int,
is A<Int>,
Expand Down
2 changes: 1 addition & 1 deletion test/Parse/matching_patterns_reference_bindings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ case (inout a, inout a): // expected-error {{invalid redeclaration of 'a'}}

var e : Any = 0

switch e { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch e { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
// 'is' pattern.
case is Int,
is A<Int>,
Expand Down
18 changes: 9 additions & 9 deletions test/Parse/switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ default:
}

// Multiple cases per case block
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
case 1:
x = 0
Expand All @@ -83,7 +83,7 @@ default:
x = 0
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0:
x = 0
case 1: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
Expand All @@ -95,7 +95,7 @@ case 0:
default: // expected-error {{'default' label in a 'switch' must have at least one executable statement}} {{9-9= break}}
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0:
; // expected-error {{';' statements are not allowed}} {{3-5=}}
case 1:
Expand Down Expand Up @@ -142,22 +142,22 @@ default: // expected-error{{additional 'case' blocks cannot appear after the 'de
x = 0
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
default where x == 0: // expected-error{{'default' cannot be used with a 'where' guard expression}}
x = 0
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
case 1:
x = 0
}

switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
case 0:
x = 0
case 1: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
Expand Down Expand Up @@ -299,7 +299,7 @@ func patternVarDiffMutability(x: Int, y: Double) {
}

func test_label(x : Int) {
Gronk: // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
Gronk: // expected-error {{switch must be exhaustive}} expected-note{{add a default clause}}
switch x {
case 42: return
}
Expand Down Expand Up @@ -637,7 +637,7 @@ func testReturnBeforeIncompleteUnknownDefault() {
}

func testReturnBeforeIncompleteUnknownDefault2() {
switch x { // expected-error {{switch must be exhaustive}} expected-note {{do you want to add a default clause?}}
switch x { // expected-error {{switch must be exhaustive}} expected-note {{add a default clause}}
case 1:
return
@unknown // expected-error {{unknown attribute 'unknown'}}
Expand Down
2 changes: 1 addition & 1 deletion test/Parse/switch_incomplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// <rdar://problem/15971438> Incomplete switch was parsing to an AST that
// triggered an assertion failure.
// expected-error@+1 {{switch must be exhaustive}} expected-note@+1{{do you want to add a default clause?}}
// expected-error@+1 {{switch must be exhaustive}} expected-note@+1{{add a default clause}}
switch 1 { // expected-note{{to match this opening '{'}}
case 1: // expected-error@+1{{expected '}' at end of 'switch' statement}}
2 changes: 1 addition & 1 deletion test/Sema/accessibility_private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Sub : Container {

protocol VeryImportantProto {
associatedtype Assoc
var value: Int { get set } // expected-note {{protocol requires property 'value' with type 'Int'; do you want to add a stub?}}
var value: Int { get set } // expected-note {{protocol requires property 'value' with type 'Int'; add a stub for conformance}}
}

private struct VIPPrivateType : VeryImportantProto {
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/call_as_function_protocol.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift

protocol P0 {
// expected-note @+1 {{protocol requires function 'callAsFunction()' with type '() -> Missing'; do you want to add a stub?}}
// expected-note @+1 {{protocol requires function 'callAsFunction()' with type '() -> Missing'; add a stub for conformance}}
func callAsFunction() -> Self
}
func testProtocol(_ x: P0) {
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/circular_decl_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct SomeStruct<A> {

// <rdar://problem/27680407> Infinite recursion when using fully-qualified associatedtype name that has not been defined with typealias
protocol rdar27680407Proto {
associatedtype T // expected-note {{protocol requires nested type 'T'; do you want to add it?}}
associatedtype T // expected-note {{protocol requires nested type 'T'; add nested type 'T' for conformance}}

init(value: T)
}
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/const_pass_as_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main_member(_ u: Utils, _ i: Int, _ d: Double, _ s: String) {
}

protocol ConstFan {
static _const var v: String { get } // expected-note {{protocol requires property 'v' with type 'String'; do you want to add a stub?}}
static _const var v: String { get } // expected-note {{protocol requires property 'v' with type 'String'; add a stub for conformance}}
}

class ConstFanClass1: ConstFan { // expected-error {{type 'ConstFanClass1' does not conform to protocol 'ConstFan'}}
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/exhaustive_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ do {

func foo(_ str: String) -> Int {
switch str { // expected-error {{switch must be exhaustive}}
// expected-note@-1 {{do you want to add a default clause?}}
// expected-note@-1 {{add a default clause}}
case let (x as Int) as Any:
return x
}
Expand Down
8 changes: 4 additions & 4 deletions test/Sema/fixits-derived-conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import Types

extension GenericEnum: Equatable { }
// expected-error@-1 {{extension outside of file declaring generic enum 'GenericEnum' prevents automatic synthesis of '==' for protocol 'Equatable'}}
// expected-note@-2 {{do you want to add protocol stubs?}}{{35-35=\n public static func == (lhs: GenericEnum, rhs: GenericEnum) -> Bool {\n <#code#>\n \}\n}}
// expected-note@-2 {{add stubs for conformance}}{{35-35=\n public static func == (lhs: GenericEnum, rhs: GenericEnum) -> Bool {\n <#code#>\n \}\n}}

extension Struct: Equatable { }
// expected-error@-1 {{extension outside of file declaring struct 'Struct' prevents automatic synthesis of '==' for protocol 'Equatable'}}
// expected-note@-2 {{do you want to add protocol stubs?}}{{30-30=\n public static func == (lhs: Struct, rhs: Struct) -> Bool {\n <#code#>\n \}\n}}
// expected-note@-2 {{add stubs for conformance}}{{30-30=\n public static func == (lhs: Struct, rhs: Struct) -> Bool {\n <#code#>\n \}\n}}
extension GenericStruct: Equatable { }
// expected-error@-1 {{extension outside of file declaring generic struct 'GenericStruct' prevents automatic synthesis of '==' for protocol 'Equatable'}}
// expected-note@-2 {{do you want to add protocol stubs?}}{{37-37=\n public static func == (lhs: GenericStruct, rhs: GenericStruct) -> Bool {\n <#code#>\n \}\n}}
// expected-note@-2 {{add stubs for conformance}}{{37-37=\n public static func == (lhs: GenericStruct, rhs: GenericStruct) -> Bool {\n <#code#>\n \}\n}}

extension Enum: CaseIterable { }
// expected-error@-1 {{extension outside of file declaring enum 'Enum' prevents automatic synthesis of 'allCases' for protocol 'CaseIterable'}}
// expected-note@-2 {{do you want to add protocol stubs?}}{{31-31=\n public static var allCases: [Enum]\n}}
// expected-note@-2 {{add stubs for conformance}}{{31-31=\n public static var allCases: [Enum]\n}}

Loading