Skip to content

Commit 02d5401

Browse files
committed
[CSDiagnostics] Don't mention special names in requirement diagnostics
Instead of `initializer 'init' of ...` diagnostic should only mention kind e.g. `initializer of ...` of the declaration with a special name.
1 parent 5ff0bab commit 02d5401

File tree

9 files changed

+34
-32
lines changed

9 files changed

+34
-32
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,23 +1541,24 @@ ERROR(types_not_equal,none,
15411541
ERROR(type_does_not_conform_owner,none,
15421542
"%0 requires that %1 conform to %2", (Type, Type, Type))
15431543
ERROR(type_does_not_conform_in_decl_ref,none,
1544-
"referencing %0 %1 on %2 requires that %3 conform to %4",
1545-
(DescriptiveDeclKind, DeclName, Type, Type, Type))
1544+
"referencing %0 %select{%2 |}1on %3 requires that %4 conform to %5",
1545+
(DescriptiveDeclKind, bool, DeclName, Type, Type, Type))
15461546
ERROR(type_does_not_conform_decl_owner,none,
1547-
"%0 %1 requires that %2 conform to %3",
1548-
(DescriptiveDeclKind, DeclName, Type, Type))
1547+
"%0 %select{%2 |}1requires that %3 conform to %4",
1548+
(DescriptiveDeclKind, bool, DeclName, Type, Type))
15491549
ERROR(types_not_equal_decl,none,
1550-
"%0 %1 requires the types %2 and %3 be equivalent",
1551-
(DescriptiveDeclKind, DeclName, Type, Type))
1550+
"%0 %select{%2 |}1requires the types %3 and %4 be equivalent",
1551+
(DescriptiveDeclKind, bool, DeclName, Type, Type))
15521552
ERROR(types_not_equal_in_decl_ref,none,
1553-
"referencing %0 %1 on %2 requires the types %3 and %4 be equivalent",
1554-
(DescriptiveDeclKind, DeclName, Type, Type, Type))
1553+
"referencing %0 %select{%2 |}1on %3 requires the types "
1554+
"%4 and %5 be equivalent",
1555+
(DescriptiveDeclKind, bool, DeclName, Type, Type, Type))
15551556
ERROR(types_not_inherited_decl,none,
1556-
"%0 %1 requires that %2 inherit from %3",
1557-
(DescriptiveDeclKind, DeclName, Type, Type))
1557+
"%0 %select{%2 |}1requires that %3 inherit from %4",
1558+
(DescriptiveDeclKind, bool, DeclName, Type, Type))
15581559
ERROR(types_not_inherited_in_decl_ref,none,
1559-
"referencing %0 %1 on %2 requires that %3 inherit from %4",
1560-
(DescriptiveDeclKind, DeclName, Type, Type, Type))
1560+
"referencing %0 %select{%2 |}1on %3 requires that %4 inherit from %5",
1561+
(DescriptiveDeclKind, bool, DeclName, Type, Type, Type))
15611562
NOTE(where_requirement_failure_one_subst,none,
15621563
"where %0 = %1", (Type, Type))
15631564
NOTE(where_requirement_failure_both_subst,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ bool RequirementFailure::diagnoseAsError() {
141141
const auto *reqDC = getRequirementDC();
142142
auto *genericCtx = AffectedDecl->getAsGenericContext();
143143

144+
auto declName = AffectedDecl->getFullName();
144145
if (reqDC != genericCtx) {
145146
auto *NTD = reqDC->getSelfNominalTypeDecl();
146147
emitDiagnostic(anchor->getLoc(), getDiagnosticInRereference(),
147-
AffectedDecl->getDescriptiveKind(),
148-
AffectedDecl->getFullName(), NTD->getDeclaredType(),
149-
getLHS(), getRHS());
148+
AffectedDecl->getDescriptiveKind(), declName.isSpecial(),
149+
declName, NTD->getDeclaredType(), getLHS(), getRHS());
150150
} else {
151151
emitDiagnostic(anchor->getLoc(), getDiagnosticOnDecl(),
152-
AffectedDecl->getDescriptiveKind(),
153-
AffectedDecl->getFullName(), getLHS(), getRHS());
152+
AffectedDecl->getDescriptiveKind(), declName.isSpecial(),
153+
declName, getLHS(), getRHS());
154154
}
155155

156156
emitRequirementNote(reqDC->getAsDecl());

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ class FailureDiagnostic {
149149
class RequirementFailure : public FailureDiagnostic {
150150
protected:
151151
using PathEltKind = ConstraintLocator::PathElementKind;
152-
using DiagOnDecl = Diag<DescriptiveDeclKind, DeclName, Type, Type>;
153-
using DiagInReference = Diag<DescriptiveDeclKind, DeclName, Type, Type, Type>;
152+
using DiagOnDecl = Diag<DescriptiveDeclKind, bool, DeclName, Type, Type>;
153+
using DiagInReference =
154+
Diag<DescriptiveDeclKind, bool, DeclName, Type, Type, Type>;
154155
using DiagAsNote = Diag<Type, Type, Type, Type, StringRef>;
155156

156157
const ValueDecl *AffectedDecl;

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ func platypus<T>(a: [T]) {
11991199
func badTypes() {
12001200
let sequence:AnySequence<[Int]> = AnySequence() { AnyIterator() { [3] }}
12011201
let array = [Int](sequence)
1202-
// expected-error@-1 {{initializer 'init' requires the types 'Int' and '[Int]' be equivalent}}
1202+
// expected-error@-1 {{initializer requires the types 'Int' and '[Int]' be equivalent}}
12031203
}
12041204

12051205
// rdar://34357545

test/Constraints/generics.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ struct V27515965 {
253253

254254
func test(x: S27515965) -> V27515965 {
255255
return V27515965(x)
256-
// expected-error@-1 {{initializer 'init' requires the types 'Any' and 'Float' be equivalent}}
256+
// expected-error@-1 {{initializer requires the types 'Any' and 'Float' be equivalent}}
257257
}
258258

259259
protocol BaseProto {}
@@ -331,14 +331,14 @@ func testFixIts() {
331331
_ = AnyClassAndProtoBound() // expected-error {{generic parameter 'Foo' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{28-28=<<#Foo: SubProto & AnyObject#>>}}
332332
_ = AnyClassAndProtoBound2() // expected-error {{generic parameter 'Foo' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{29-29=<<#Foo: SubProto & AnyObject#>>}}
333333

334-
_ = ClassAndProtoBound() // expected-error {{referencing initializer 'init()' on 'ClassAndProtoBound' requires that 'X' conform to 'SubProto'}}
334+
_ = ClassAndProtoBound() // expected-error {{referencing initializer on 'ClassAndProtoBound' requires that 'X' conform to 'SubProto'}}
335335

336336
_ = ClassAndProtosBound()
337-
// expected-error@-1 {{referencing initializer 'init()' on 'ClassAndProtosBound' requires that 'X' conform to 'NSCopyish'}}
338-
// expected-error@-2 {{referencing initializer 'init()' on 'ClassAndProtosBound' requires that 'X' conform to 'SubProto'}}
337+
// expected-error@-1 {{referencing initializer on 'ClassAndProtosBound' requires that 'X' conform to 'NSCopyish'}}
338+
// expected-error@-2 {{referencing initializer on 'ClassAndProtosBound' requires that 'X' conform to 'SubProto'}}
339339
_ = ClassAndProtosBound2()
340-
// expected-error@-1 {{referencing initializer 'init()' on 'ClassAndProtosBound2' requires that 'X' conform to 'NSCopyish'}}
341-
// expected-error@-2 {{referencing initializer 'init()' on 'ClassAndProtosBound2' requires that 'X' conform to 'SubProto'}}
340+
// expected-error@-1 {{referencing initializer on 'ClassAndProtosBound2' requires that 'X' conform to 'NSCopyish'}}
341+
// expected-error@-2 {{referencing initializer on 'ClassAndProtosBound2' requires that 'X' conform to 'SubProto'}}
342342

343343
_ = Pair() // expected-error {{generic parameter 'T' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{11-11=<Any, Any>}}
344344
_ = Pair(first: S()) // expected-error {{generic parameter 'U' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{11-11=<S, Any>}}
@@ -610,7 +610,7 @@ func rdar40537858() {
610610
}
611611

612612
var arr: [S] = []
613-
_ = List(arr, id: \.id) // expected-error {{referencing initializer 'init(_:id:)' on 'List' requires that 'S.Id' conform to 'Hashable'}}
613+
_ = List(arr, id: \.id) // expected-error {{referencing initializer on 'List' requires that 'S.Id' conform to 'Hashable'}}
614614

615615
enum E<T: P> { // expected-note 2 {{where 'T' = 'S'}}
616616
case foo(T)

test/Constraints/rdar44569159.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ struct A {
1313

1414
func foo(_ v: Double) {
1515
_ = A()[S(value: v)]
16-
// expected-error@-1 {{subscript 'subscript' requires that 'Double' conform to 'P'}}
17-
// expected-error@-2 {{referencing initializer 'init(value:)' on 'S' requires that 'Double' conform to 'P'}}
16+
// expected-error@-1 {{subscript requires that 'Double' conform to 'P'}}
17+
// expected-error@-2 {{referencing initializer on 'S' requires that 'Double' conform to 'P'}}
1818
}

test/Constraints/tuple.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct MagicKingdom<K> : Kingdom {
169169
}
170170
func magify<T>(_ t: T) -> MagicKingdom<T> { return MagicKingdom() }
171171
func foo(_ pair: (Int, Int)) -> Victory<(x: Int, y: Int)> {
172-
return Victory(magify(pair)) // expected-error {{initializer 'init' requires the types '(x: Int, y: Int)' and '(Int, Int)' be equivalent}}
172+
return Victory(magify(pair)) // expected-error {{initializer requires the types '(x: Int, y: Int)' and '(Int, Int)' be equivalent}}
173173
}
174174

175175

test/Serialization/builtin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ var a : TheBuiltinInt64
1111

1212
// Check that it really is Builtin.Int64.
1313
var wrapped = Int64(a) // okay
14-
var badWrapped = Int32(a) // expected-error{{initializer 'init' requires that 'TheBuiltinInt64' conform to 'BinaryInteger'}}
14+
var badWrapped = Int32(a) // expected-error{{initializer requires that 'TheBuiltinInt64' conform to 'BinaryInteger'}}

test/expr/unary/keypath/salvage-with-other-type-errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct A {
2727
}
2828

2929
extension A: K {
30-
static let j = S(\A.id + "id") // expected-error {{initializer 'init' requires that 'String' conform to 'K'}}
30+
static let j = S(\A.id + "id") // expected-error {{initializer requires that 'String' conform to 'K'}}
3131
}
3232

3333
// SR-5034

0 commit comments

Comments
 (0)