Skip to content

Commit b6fd5fe

Browse files
committed
[CSDiangostics] Adjust phrasing of invalid specialization diagnostic
Instead of "a generic function" which is too abstract and not always correct, let's actually point to a kind of the declaration being referenced.
1 parent 2a6cc12 commit b6fd5fe

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,7 @@ NOTE(duplicated_key_declared_here, none,
46074607

46084608
// Generic specializations
46094609
ERROR(cannot_explicitly_specialize_function,none,
4610-
"cannot explicitly specialize a%select{| generic}0 function", (bool))
4610+
"cannot explicitly specialize %kind0", (ValueDecl *))
46114611
ERROR(not_a_generic_type,none,
46124612
"cannot specialize non-generic type %0", (Type))
46134613
ERROR(not_a_generic_macro,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9366,8 +9366,7 @@ bool ConcreteTypeSpecialization::diagnoseAsError() {
93669366
}
93679367

93689368
bool InvalidFunctionSpecialization::diagnoseAsError() {
9369-
emitDiagnostic(diag::cannot_explicitly_specialize_function,
9370-
bool(Decl->getAsGenericContext()));
9369+
emitDiagnostic(diag::cannot_explicitly_specialize_function, Decl);
93719370
emitDiagnosticAt(Decl, diag::decl_declared_here, Decl);
93729371
return true;
93739372
}

test/Parse/generic_disambiguation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ _ = a>(b)
4242
_ = a > (b)
4343

4444
generic<Int>(0)
45-
// expected-swift5-warning@-1{{cannot explicitly specialize a generic function}}
46-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
45+
// expected-swift5-warning@-1{{cannot explicitly specialize global function 'generic'}}
46+
// expected-swift6-error@-2 {{cannot explicitly specialize global function 'generic'}}
4747

4848
A<B>.c()
4949
A<A<B>>.c()

test/Sema/generic_specialization.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ extension Int {
1616
// https://github.com/swiftlang/swift/issues/74857
1717
func test(i: Int) {
1818
let _ = i.foo<Int>()
19-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
20-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
19+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'foo()'}}
20+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'foo()'}}
2121

2222
let _ = i.gen<Int>()
23-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
24-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
23+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'gen()'}}
24+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'gen()'}}
2525
// expected-error@-3 {{generic parameter 'T' could not be inferred}}
2626

2727
let _ = 0.foo<Int>()
28-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
29-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
28+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'foo()'}}
29+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'foo()'}}
3030

3131
let _ = i.gen<Int>
32-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
33-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
32+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'gen()'}}
33+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'gen()'}}
3434
// expected-error@-3 {{generic parameter 'T' could not be inferred}}
3535
let _ = i.bar<Int>
3636
// expected-swift5-error@-1 {{cannot specialize non-generic type 'Int'}}
@@ -45,8 +45,8 @@ extension Bool {
4545
}
4646

4747
let _: () -> Bool = false.foo<Int>
48-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
49-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
48+
// expected-swift5-warning@-1 {{cannot explicitly specialize instance method 'foo()'}}
49+
// expected-swift6-error@-2 {{cannot explicitly specialize instance method 'foo()'}}
5050

5151
func foo(_ x: Int) {
5252
_ = {
@@ -62,6 +62,6 @@ do {
6262
}
6363

6464
_ = Test.init<Int>({ (_: Int) -> Void in })
65-
// expected-swift5-warning@-1 {{cannot explicitly specialize a generic function}}
66-
// expected-swift6-error@-2 {{cannot explicitly specialize a generic function}}
65+
// expected-swift5-warning@-1 {{cannot explicitly specialize initializer 'init(_:)'}}
66+
// expected-swift6-error@-2 {{cannot explicitly specialize initializer 'init(_:)'}}
6767
}

0 commit comments

Comments
 (0)