Skip to content

Commit 1184492

Browse files
LucianoPAlmeidaCodaFi
authored andcommitted
[Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode * [test] Removing note from test where there is no -diagnostics-editor-mode flag * Formatting modified code * [tests] Fixing tests under validation-tests
1 parent d9b03a5 commit 1184492

24 files changed

+60
-63
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,8 +2758,10 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind) {
27582758
// because editor may assume the fixit is in the same file with the note.
27592759
Diags.diagnose(MissingTypeWitness, diag::no_witnesses_type,
27602760
MissingTypeWitness->getName());
2761-
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general).
2762-
fixItInsertAfter(FixitLocation, FixIt);
2761+
if (EditorMode) {
2762+
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general)
2763+
.fixItInsertAfter(FixitLocation, FixIt);
2764+
}
27632765
}
27642766
continue;
27652767
}
@@ -2772,15 +2774,17 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind) {
27722774
// we can directly associate the fixit with the note issued to the
27732775
// requirement.
27742776
Diags.diagnose(VD, diag::no_witnesses, getRequirementKind(VD),
2775-
VD->getFullName(), RequirementType, true).
2776-
fixItInsertAfter(FixitLocation, FixIt);
2777+
VD->getFullName(), RequirementType, true)
2778+
.fixItInsertAfter(FixitLocation, FixIt);
27772779
} else {
27782780
// Otherwise, we have to issue another note to carry the fixit,
27792781
// because editor may assume the fixit is in the same file with the note.
27802782
Diags.diagnose(VD, diag::no_witnesses, getRequirementKind(VD),
27812783
VD->getFullName(), RequirementType, false);
2782-
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general).
2783-
fixItInsertAfter(FixitLocation, FixIt);
2784+
if (EditorMode) {
2785+
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general)
2786+
.fixItInsertAfter(FixitLocation, FixIt);
2787+
}
27842788
}
27852789
} else {
27862790
Diags.diagnose(VD, diag::no_witnesses, getRequirementKind(VD),

test/ClangImporter/objc_parse.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,13 @@ class ProtocolAdopter2 : FooProto {
371371
set { /* do nothing! */ }
372372
}
373373
}
374-
class ProtocolAdopterBad1 : FooProto { // expected-error {{type 'ProtocolAdopterBad1' does not conform to protocol 'FooProto'}} expected-note {{do you want to add protocol stubs?}}
374+
class ProtocolAdopterBad1 : FooProto { // expected-error {{type 'ProtocolAdopterBad1' does not conform to protocol 'FooProto'}}
375375
@objc var bar: Int = 0 // expected-note {{candidate has non-matching type 'Int'}}
376376
}
377-
class ProtocolAdopterBad2 : FooProto { // expected-error {{type 'ProtocolAdopterBad2' does not conform to protocol 'FooProto'}} expected-note {{do you want to add protocol stubs?}}
377+
class ProtocolAdopterBad2 : FooProto { // expected-error {{type 'ProtocolAdopterBad2' does not conform to protocol 'FooProto'}}
378378
let bar: CInt = 0 // expected-note {{candidate is not settable, but protocol requires it}}
379379
}
380-
class ProtocolAdopterBad3 : FooProto { // expected-error {{type 'ProtocolAdopterBad3' does not conform to protocol 'FooProto'}} expected-note {{do you want to add protocol stubs?}}
380+
class ProtocolAdopterBad3 : FooProto { // expected-error {{type 'ProtocolAdopterBad3' does not conform to protocol 'FooProto'}}
381381
var bar: CInt { // expected-note {{candidate is not settable, but protocol requires it}}
382382
return 42
383383
}

test/ClangImporter/subclass_existentials.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SwiftLaundryService : NSLaundry {
2121

2222
// FIXME: Consider better diagnostics here.
2323

24-
class OldSwiftLaundryService : NSLaundry { // expected-note 3 {{do you want to add protocol stubs?}}
24+
class OldSwiftLaundryService : NSLaundry {
2525
// expected-error@-1 {{type 'OldSwiftLaundryService' does not conform to protocol 'NSLaundry'}}
2626

2727
var g: Coat? = nil

test/Constraints/invalid_stdlib_2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
class Dictionary<K, V> : ExpressibleByDictionaryLiteral { // expected-error {{type 'Dictionary<K, V>' does not conform to protocol 'ExpressibleByDictionaryLiteral'}} expected-note {{do you want to add protocol stubs?}}
3+
class Dictionary<K, V> : ExpressibleByDictionaryLiteral { // expected-error {{type 'Dictionary<K, V>' does not conform to protocol 'ExpressibleByDictionaryLiteral'}}
44
typealias Key = K
55
typealias Value = V
66
init(dictionaryLiteral xs: (K)...){} // expected-note {{candidate has non-matching type '(dictionaryLiteral: (K)...)'}}

test/Generics/inheritance.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func testGenericInherit() {
5656

5757

5858
struct SS<T> : T { } // expected-error{{inheritance from non-protocol type 'T'}}
59-
enum SE<T> : T { case X } // expected-error{{raw type 'T' is not expressible by a string, integer, or floating-point literal}} // expected-error {{SE<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}} expected-note {{do you want to add protocol stubs?}}
59+
enum SE<T> : T { case X } // expected-error{{raw type 'T' is not expressible by a string, integer, or floating-point literal}} // expected-error {{SE<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}}
6060

6161
// Also need Equatable for init?(RawValue)
62-
enum SE2<T : ExpressibleByIntegerLiteral> // expected-note {{do you want to add protocol stubs?}}
62+
enum SE2<T : ExpressibleByIntegerLiteral>
6363
: T // expected-error {{'SE2<T>' declares raw type 'T', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error{{RawRepresentable conformance cannot be synthesized because raw type 'T' is not Equatable}}
6464
{ case X }
6565

test/IDE/print_ast_tc_decls_errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} //
117117
// NO-TYREPR: {{^}}enum EnumWithInheritance2 : <<error type>>, <<error type>> {{{$}}
118118
// TYREPR: {{^}}enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}}
119119

120-
enum EnumWithInheritance3 : FooClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}} expected-note {{do you want to add protocol stubs?}}
120+
enum EnumWithInheritance3 : FooClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}}
121121
// expected-error@-1{{'EnumWithInheritance3' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
122122
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
123123
// NO-TYREPR: {{^}}enum EnumWithInheritance3 : <<error type>> {{{$}}
124124
// TYREPR: {{^}}enum EnumWithInheritance3 : FooClass {{{$}}
125125

126-
enum EnumWithInheritance4 : FooClass, FooProtocol { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}} expected-note {{do you want to add protocol stubs?}}
126+
enum EnumWithInheritance4 : FooClass, FooProtocol { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}}
127127
// expected-error@-1{{'EnumWithInheritance4' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
128128
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
129129
// NO-TYREPR: {{^}}enum EnumWithInheritance4 : <<error type>>, FooProtocol {{{$}}
130130
// TYREPR: {{^}}enum EnumWithInheritance4 : FooClass, FooProtocol {{{$}}
131131

132-
enum EnumWithInheritance5 : FooClass, BarClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}} expected-error {{multiple enum raw types 'FooClass' and 'BarClass'}} expected-note {{do you want to add protocol stubs?}}
132+
enum EnumWithInheritance5 : FooClass, BarClass { case X } // expected-error {{raw type 'FooClass' is not expressible by a string, integer, or floating-point literal}} expected-error {{multiple enum raw types 'FooClass' and 'BarClass'}}
133133
// expected-error@-1{{'EnumWithInheritance5' declares raw type 'FooClass', but does not conform to RawRepresentable and conformance could not be synthesized}}
134134
// expected-error@-2{{RawRepresentable conformance cannot be synthesized because raw type 'FooClass' is not Equatable}}
135135
// NO-TYREPR: {{^}}enum EnumWithInheritance5 : <<error type>>, <<error type>> {{{$}}

test/Parse/enum.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ enum Recovery6 {
130130
case Tusk, // expected-error {{expected identifier after comma in enum 'case' declaration}}
131131
}
132132

133-
enum RawTypeEmpty : Int {} // expected-error {{an enum with no cases cannot declare a raw type}} expected-note {{do you want to add protocol stubs?}}
133+
enum RawTypeEmpty : Int {} // expected-error {{an enum with no cases cannot declare a raw type}}
134134
// expected-error@-1{{'RawTypeEmpty' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
135135

136136
enum Raw : Int {
@@ -146,7 +146,7 @@ enum RawTypeNotFirst : RawTypeNotFirstProtocol, Int { // expected-error {{raw ty
146146
case E
147147
}
148148

149-
enum ExpressibleByRawTypeNotLiteral : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by a string, integer, or floating-point literal}} expected-note {{do you want to add protocol stubs?}}
149+
enum ExpressibleByRawTypeNotLiteral : Array<Int> { // expected-error {{raw type 'Array<Int>' is not expressible by a string, integer, or floating-point literal}}
150150
// expected-error@-1{{'ExpressibleByRawTypeNotLiteral' declares raw type 'Array<Int>', but does not conform to RawRepresentable and conformance could not be synthesized}}
151151
case Ladd, Elliott, Sixteenth, Harrison
152152
}
@@ -170,7 +170,7 @@ enum RawTypeCircularityB : RawTypeCircularityA, ExpressibleByIntegerLiteral { //
170170
struct ExpressibleByFloatLiteralOnly : ExpressibleByFloatLiteral {
171171
init(floatLiteral: Double) {}
172172
}
173-
enum ExpressibleByRawTypeNotIntegerLiteral : ExpressibleByFloatLiteralOnly { // expected-error {{'ExpressibleByRawTypeNotIntegerLiteral' declares raw type 'ExpressibleByFloatLiteralOnly', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error {{RawRepresentable conformance cannot be synthesized because raw type 'ExpressibleByFloatLiteralOnly' is not Equatable}} expected-note {{do you want to add protocol stubs?}}
173+
enum ExpressibleByRawTypeNotIntegerLiteral : ExpressibleByFloatLiteralOnly { // expected-error {{'ExpressibleByRawTypeNotIntegerLiteral' declares raw type 'ExpressibleByFloatLiteralOnly', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-error {{RawRepresentable conformance cannot be synthesized because raw type 'ExpressibleByFloatLiteralOnly' is not Equatable}}
174174
case Everett // expected-error {{enum cases require explicit raw values when the raw type is not expressible by integer or string literal}}
175175
case Flanders
176176
}
@@ -184,13 +184,13 @@ enum RawTypeWithNegativeValues : Int {
184184
case AutoIncAcrossZero = -1, Zero, One
185185
}
186186

187-
enum RawTypeWithUnicodeScalarValues : UnicodeScalar { // expected-error {{'RawTypeWithUnicodeScalarValues' declares raw type 'UnicodeScalar' (aka 'Unicode.Scalar'), but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
187+
enum RawTypeWithUnicodeScalarValues : UnicodeScalar { // expected-error {{'RawTypeWithUnicodeScalarValues' declares raw type 'UnicodeScalar' (aka 'Unicode.Scalar'), but does not conform to RawRepresentable and conformance could not be synthesized}}
188188
case Kearney = "K"
189189
case Lovejoy // expected-error {{enum cases require explicit raw values when the raw type is not expressible by integer or string literal}}
190190
case Marshall = "M"
191191
}
192192

193-
enum RawTypeWithCharacterValues : Character { // expected-error {{'RawTypeWithCharacterValues' declares raw type 'Character', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
193+
enum RawTypeWithCharacterValues : Character { // expected-error {{'RawTypeWithCharacterValues' declares raw type 'Character', but does not conform to RawRepresentable and conformance could not be synthesized}}
194194
case First = ""
195195
case Second // expected-error {{enum cases require explicit raw values when the raw type is not expressible by integer or string literal}}
196196
case Third = ""
@@ -203,11 +203,11 @@ enum RawTypeWithCharacterValues_Correct : Character {
203203
case Fourth = "\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}" // ok
204204
}
205205

206-
enum RawTypeWithCharacterValues_Error1 : Character { // expected-error {{'RawTypeWithCharacterValues_Error1' declares raw type 'Character', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
206+
enum RawTypeWithCharacterValues_Error1 : Character { // expected-error {{'RawTypeWithCharacterValues_Error1' declares raw type 'Character', but does not conform to RawRepresentable and conformance could not be synthesized}}
207207
case First = "abc" // expected-error {{cannot convert value of type 'String' to raw type 'Character'}}
208208
}
209209

210-
enum RawTypeWithFloatValues : Float { // expected-error {{'RawTypeWithFloatValues' declares raw type 'Float', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
210+
enum RawTypeWithFloatValues : Float { // expected-error {{'RawTypeWithFloatValues' declares raw type 'Float', but does not conform to RawRepresentable and conformance could not be synthesized}}
211211
case Northrup = 1.5
212212
case Overton // expected-error {{enum case must declare a raw value when the preceding raw value is not an integer}}
213213
case Pettygrove = 2.25
@@ -318,12 +318,12 @@ enum NonliteralRawValue : Int {
318318
case Yeon = 100 + 20 + 3 // expected-error {{raw value for enum case must be a literal}}
319319
}
320320

321-
enum RawTypeWithPayload : Int { // expected-error {{'RawTypeWithPayload' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{declared raw type 'Int' here}} expected-note {{declared raw type 'Int' here}} expected-note {{do you want to add protocol stubs?}}
321+
enum RawTypeWithPayload : Int { // expected-error {{'RawTypeWithPayload' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{declared raw type 'Int' here}} expected-note {{declared raw type 'Int' here}}
322322
case Powell(Int) // expected-error {{enum with raw type cannot have cases with arguments}}
323323
case Terwilliger(Int) = 17 // expected-error {{enum with raw type cannot have cases with arguments}}
324324
}
325325

326-
enum RawTypeMismatch : Int { // expected-error {{'RawTypeMismatch' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
326+
enum RawTypeMismatch : Int { // expected-error {{'RawTypeMismatch' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
327327
case Barbur = "foo" // expected-error {{}}
328328
}
329329

@@ -343,12 +343,12 @@ enum DuplicateMembers3 {
343343
case Foo(Int) // expected-error {{invalid redeclaration of 'Foo'}}
344344
}
345345

346-
enum DuplicateMembers4 : Int { // expected-error {{'DuplicateMembers4' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
346+
enum DuplicateMembers4 : Int { // expected-error {{'DuplicateMembers4' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
347347
case Foo = 1 // expected-note {{'Foo' previously declared here}}
348348
case Foo = 2 // expected-error {{invalid redeclaration of 'Foo'}}
349349
}
350350

351-
enum DuplicateMembers5 : Int { // expected-error {{'DuplicateMembers5' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
351+
enum DuplicateMembers5 : Int { // expected-error {{'DuplicateMembers5' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
352352
case Foo = 1 // expected-note {{'Foo' previously declared here}}
353353
case Foo = 1 + 1 // expected-error {{invalid redeclaration of 'Foo'}} expected-error {{raw value for enum case must be a literal}}
354354
}
@@ -359,7 +359,7 @@ enum DuplicateMembers6 {
359359
case Foo // expected-error {{invalid redeclaration of 'Foo'}}
360360
}
361361

362-
enum DuplicateMembers7 : String { // expected-error {{'DuplicateMembers7' declares raw type 'String', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
362+
enum DuplicateMembers7 : String { // expected-error {{'DuplicateMembers7' declares raw type 'String', but does not conform to RawRepresentable and conformance could not be synthesized}}
363363
case Foo // expected-note {{'Foo' previously declared here}}
364364
case Foo = "Bar" // expected-error {{invalid redeclaration of 'Foo'}}
365365
}
@@ -411,7 +411,7 @@ enum ManyLiteralA : ManyLiteralable {
411411
case B = 0 // expected-error {{raw value for enum case is not unique}}
412412
}
413413

414-
enum ManyLiteralB : ManyLiteralable { // expected-error {{'ManyLiteralB' declares raw type 'ManyLiteralable', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
414+
enum ManyLiteralB : ManyLiteralable { // expected-error {{'ManyLiteralB' declares raw type 'ManyLiteralable', but does not conform to RawRepresentable and conformance could not be synthesized}}
415415
case A = "abc"
416416
case B // expected-error {{enum case must declare a raw value when the preceding raw value is not an integer}}
417417
}
@@ -440,7 +440,7 @@ enum RawValueBTest: Double, RawValueB {
440440
case A, B
441441
}
442442

443-
enum foo : String { // expected-error {{'foo' declares raw type 'String', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
443+
enum foo : String { // expected-error {{'foo' declares raw type 'String', but does not conform to RawRepresentable and conformance could not be synthesized}}
444444
case bar = nil // expected-error {{cannot convert 'nil' to raw type 'String'}}
445445
}
446446

test/Parse/objc_enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Bar {
3030
}
3131

3232
// <rdar://problem/23681566> @objc enums with payloads rejected with no source location info
33-
@objc enum r23681566 : Int32 { // expected-error {{'r23681566' declares raw type 'Int32', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{declared raw type 'Int32' here}} expected-note {{do you want to add protocol stubs?}}
33+
@objc enum r23681566 : Int32 { // expected-error {{'r23681566' declares raw type 'Int32', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{declared raw type 'Int32' here}}
3434
case Foo(progress: Int) // expected-error {{enum with raw type cannot have cases with arguments}}
3535
}
3636

test/Parse/recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ let tryx = 123 // expected-error 2 {{invalid character in source file
761761

762762

763763
// <rdar://problem/21369926> Malformed Swift Enums crash playground service
764-
enum Rank: Int { // expected-error {{'Rank' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}} expected-note {{do you want to add protocol stubs?}}
764+
enum Rank: Int { // expected-error {{'Rank' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
765765
case Ace = 1
766766
case Two = 2.1 // expected-error {{cannot convert value of type 'Double' to raw type 'Int'}}
767767
}

0 commit comments

Comments
 (0)