Skip to content

Commit 7687293

Browse files
committed
[Diagnostics] Adjust the description of existential types for the
type_cannot_conform diagnostic message.
1 parent 2a7e009 commit 7687293

File tree

9 files changed

+17
-17
lines changed

9 files changed

+17
-17
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ ERROR(use_of_equal_instead_of_equality,none,
16611661
"use of '=' in a boolean context, did you mean '=='?", ())
16621662

16631663
ERROR(type_cannot_conform, none,
1664-
"%select{|protocol }0type %1 cannot conform to %2; "
1664+
"%select{|value of protocol }0type %1 cannot conform to %2; "
16651665
"only struct/enum/class types can conform to protocols",
16661666
(bool, Type, Type))
16671667
NOTE(required_by_opaque_return,none,

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func r22459135() {
191191

192192
// <rdar://problem/19710848> QoI: Friendlier error message for "[] as Set"
193193
// <rdar://problem/22326930> QoI: "argument for generic parameter 'Element' could not be inferred" lacks context
194-
_ = [] as Set // expected-error {{protocol type 'Any' cannot conform to 'Hashable'; only struct/enum/class types can conform to protocols}}
194+
_ = [] as Set // expected-error {{value of protocol type 'Any' cannot conform to 'Hashable'; only struct/enum/class types can conform to protocols}}
195195
// expected-note@-1 {{required by generic struct 'Set' where 'Element' = 'Any'}}
196196

197197

test/Constraints/operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func rdar46459603() {
220220
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'Dictionary<String, E>.Values' and '[E]'}}
221221
// expected-note@-2 {{expected an argument list of type '(Self, Self)'}}
222222
_ = [arr.values] == [[e]]
223-
// expected-error@-1 {{protocol type 'Any' cannot conform to 'Equatable'; only struct/enum/class types can conform to protocols}}
223+
// expected-error@-1 {{value of protocol type 'Any' cannot conform to 'Equatable'; only struct/enum/class types can conform to protocols}}
224224
// expected-note@-2 {{requirement from conditional conformance of '[Any]' to 'Equatable'}}
225225
}
226226

test/Generics/conditional_conformances_literals.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ func combined() {
128128

129129
// Needs self conforming protocols:
130130
let _: Conforms = [[0: [1 : [works]] as Conforms]]
131-
// expected-error@-1 {{protocol type 'Conforms' cannot conform to 'Conforms'; only struct/enum/class types can conform to protocols}}
131+
// expected-error@-1 {{value of protocol type 'Conforms' cannot conform to 'Conforms'; only struct/enum/class types can conform to protocols}}
132132

133133
let _: Conforms = [[0: [1 : [fails]] as Conforms]]
134134
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
135-
// expected-error@-2 {{protocol type 'Conforms' cannot conform to 'Conforms'; only struct/enum/class types can conform to protocols}}
135+
// expected-error@-2 {{value of protocol type 'Conforms' cannot conform to 'Conforms'; only struct/enum/class types can conform to protocols}}
136136
}

test/Generics/existential_restrictions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func fAOE(_ t: AnyObject) { }
2020
func fT<T>(_ t: T) { }
2121

2222
func testPassExistential(_ p: P, op: OP, opp: OP & P, cp: CP, sp: SP, any: Any, ao: AnyObject) {
23-
fP(p) // expected-error{{protocol type 'P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
23+
fP(p) // expected-error{{value of protocol type 'P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
2424
fAO(p) // expected-error{{cannot invoke 'fAO' with an argument list of type '(P)'}} // expected-note{{expected an argument list of type '(T)'}}
2525
fAOE(p) // expected-error{{argument type 'P' does not conform to expected type 'AnyObject'}}
2626
fT(p)
@@ -34,8 +34,8 @@ func testPassExistential(_ p: P, op: OP, opp: OP & P, cp: CP, sp: SP, any: Any,
3434
fAOE(cp)
3535
fT(cp)
3636

37-
fP(opp) // expected-error{{protocol type 'OP & P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
38-
fOP(opp) // expected-error{{protocol type 'OP & P' cannot conform to 'OP'; only struct/enum/class types can conform to protocols}}
37+
fP(opp) // expected-error{{value of protocol type 'OP & P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
38+
fOP(opp) // expected-error{{value of protocol type 'OP & P' cannot conform to 'OP'; only struct/enum/class types can conform to protocols}}
3939
fAO(opp) // expected-error{{cannot invoke 'fAO' with an argument list of type '(OP & P)'}} // expected-note{{expected an argument list of type '(T)'}}
4040
fAOE(opp)
4141
fT(opp)
@@ -61,9 +61,9 @@ class GAO<T : AnyObject> {} // expected-note 2{{requirement specified as 'T' : '
6161
func blackHole(_ t: Any) {}
6262

6363
func testBindExistential() {
64-
blackHole(GP<P>()) // expected-error{{protocol type 'P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
64+
blackHole(GP<P>()) // expected-error{{value of protocol type 'P' cannot conform to 'P'; only struct/enum/class types can conform to protocols}}
6565
blackHole(GOP<OP>())
66-
blackHole(GCP<CP>()) // expected-error{{protocol type 'CP' cannot conform to 'CP'; only struct/enum/class types can conform to protocols}}
66+
blackHole(GCP<CP>()) // expected-error{{value of protocol type 'CP' cannot conform to 'CP'; only struct/enum/class types can conform to protocols}}
6767
blackHole(GAO<P>()) // expected-error{{'GAO' requires that 'P' be a class type}}
6868
blackHole(GAO<OP>())
6969
blackHole(GAO<CP>()) // expected-error{{'GAO' requires that 'CP' be a class type}}
@@ -89,5 +89,5 @@ func foo() {
8989
// generic no overloads error path. The error should actually talk
9090
// about the return type, and this can happen in other contexts as well;
9191
// <rdar://problem/21900971> tracks improving QoI here.
92-
allMine.takeAll() // expected-error{{protocol type 'Mine' cannot conform to 'Mine'; only struct/enum/class types can conform to protocols}}
92+
allMine.takeAll() // expected-error{{value of protocol type 'Mine' cannot conform to 'Mine'; only struct/enum/class types can conform to protocols}}
9393
}

test/decl/protocol/conforms/error_self_conformance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ func testSimple(error: Error) {
1111

1212
protocol ErrorRefinement : Error {}
1313
func testErrorRefinment(error: ErrorRefinement) {
14-
wantsError(error) // expected-error {{protocol type 'ErrorRefinement' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
14+
wantsError(error) // expected-error {{value of protocol type 'ErrorRefinement' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
1515
}
1616

1717
protocol OtherProtocol {}
1818
func testErrorComposition(error: Error & OtherProtocol) {
19-
wantsError(error) // expected-error {{protocol type 'Error & OtherProtocol' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
19+
wantsError(error) // expected-error {{value of protocol type 'Error & OtherProtocol' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
2020
}
2121

2222
class C {}
2323
func testErrorCompositionWithClass(error: Error & C) {
24-
wantsError(error) // expected-error {{protocol type 'C & Error' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
24+
wantsError(error) // expected-error {{value of protocol type 'C & Error' cannot conform to 'Error'; only struct/enum/class types can conform to protocols}}
2525
}

test/stmt/foreach.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func testOptionalSequence() {
179179

180180
// Crash with (invalid) for each over an existential
181181
func testExistentialSequence(s: Sequence) { // expected-error {{protocol 'Sequence' can only be used as a generic constraint because it has Self or associated type requirements}}
182-
for x in s { // expected-error {{protocol type 'Sequence' cannot conform to 'Sequence'; only struct/enum/class types can conform to protocols}}
182+
for x in s { // expected-error {{value of protocol type 'Sequence' cannot conform to 'Sequence'; only struct/enum/class types can conform to protocols}}
183183
_ = x
184184
}
185185
}

test/type/subclass_composition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func conformsTo<T1 : P2, T2 : Base<Int> & P2>(
413413
// expected-note@-2 {{expected an argument list of type '(T)'}}
414414

415415
conformsToP1(p1)
416-
// expected-error@-1 {{protocol type 'P1' cannot conform to 'P1'; only struct/enum/class types can conform to protocols}}
416+
// expected-error@-1 {{value of protocol type 'P1' cannot conform to 'P1'; only struct/enum/class types can conform to protocols}}
417417

418418
// FIXME: Following diagnostics are not great because when
419419
// `conformsTo*` methods are re-typechecked, they loose information

validation-test/compiler_crashers_fixed/00017-llvm-foldingset-llvm-attributesetnode-nodeequals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ extension Bool : BooleanProtocol {
2020
func f<T : BooleanProtocol>(_ b: T) {}
2121
// expected-note@-1 {{required by global function 'f' where 'T' = 'BooleanProtocol'}}
2222

23-
f(true as BooleanProtocol) // expected-error {{protocol type 'BooleanProtocol' cannot conform to 'BooleanProtocol'; only struct/enum/class types can conform to protocols}}
23+
f(true as BooleanProtocol) // expected-error {{value of protocol type 'BooleanProtocol' cannot conform to 'BooleanProtocol'; only struct/enum/class types can conform to protocols}}

0 commit comments

Comments
 (0)