Skip to content

Commit ff6747d

Browse files
authored
Merge pull request #10745 from ahoppen/diagnostics-adjustments-declname
[Diag] Change function diagnostics to take a DeclName parameter
2 parents 4534e2f + f35f29d commit ff6747d

File tree

12 files changed

+29
-28
lines changed

12 files changed

+29
-28
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ ERROR(optional_chain_isnt_chaining,none,
839839
ERROR(pattern_in_expr,none,
840840
"%0 cannot appear in an expression", (PatternKind))
841841
NOTE(note_call_to_operator,none,
842-
"in call to operator %0", (Identifier))
842+
"in call to operator %0", (DeclName))
843843
NOTE(note_call_to_func,none,
844-
"in call to function %0", (Identifier))
844+
"in call to function %0", (DeclName))
845845
NOTE(note_call_to_initializer,none,
846846
"in call to initializer", ())
847847
NOTE(note_init_parameter,none,
@@ -1254,7 +1254,7 @@ NOTE(unstable_mangled_name_add_objc,none,
12541254
// Generic types
12551255
ERROR(unsupported_type_nested_in_generic_function,none,
12561256
"type %0 cannot be nested in generic function %1",
1257-
(Identifier, Identifier))
1257+
(Identifier, DeclName))
12581258
ERROR(unsupported_type_nested_in_generic_closure,none,
12591259
"type %0 cannot be nested in closure in generic context",
12601260
(Identifier))
@@ -3576,12 +3576,12 @@ ERROR(fixed_layout_attr_on_internal_type,
35763576
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
35773577
"or public declarations, but %0 is "
35783578
"%select{private|fileprivate|internal|%error|%error}1",
3579-
(DeclBaseName, Accessibility))
3579+
(DeclName, Accessibility))
35803580

35813581
ERROR(versioned_attr_with_explicit_accessibility,
35823582
none, "'@_versioned' attribute can only be applied to internal "
35833583
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1",
3584-
(DeclBaseName, Accessibility))
3584+
(DeclName, Accessibility))
35853585

35863586
ERROR(versioned_attr_in_protocol,none,
35873587
"'@_versioned' attribute cannot be used in protocols", ())
@@ -3636,7 +3636,7 @@ ERROR(inlineable_decl_not_public,
36363636
//------------------------------------------------------------------------------
36373637

36383638
ERROR(specialize_attr_nongeneric_trailing_where,none,
3639-
"trailing 'where' clause in '_specialize' attribute of non-generic function %0", (Identifier))
3639+
"trailing 'where' clause in '_specialize' attribute of non-generic function %0", (DeclName))
36403640
ERROR(specialize_missing_where_clause,none,
36413641
"missing 'where' clause in '_specialize' attribute", ())
36423642
ERROR(specialize_empty_where_clause,none,

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9155,7 +9155,7 @@ void FailureDiagnosis::diagnoseUnboundArchetype(ArchetypeType *archetype,
91559155

91569156
auto decl = resolved.getDecl();
91579157
if (auto FD = dyn_cast<FuncDecl>(decl)) {
9158-
auto name = FD->getName();
9158+
auto name = FD->getFullName();
91599159
auto diagID = name.isOperator() ? diag::note_call_to_operator
91609160
: diag::note_call_to_func;
91619161
tc.diagnose(decl, diagID, name);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,8 @@ void AttributeChecker::visitSpecializeAttr(SpecializeAttr *attr) {
16421642
if (!genericSig) {
16431643
// Only generic functions are permitted to have trailing where clauses.
16441644
TC.diagnose(attr->getLocation(),
1645-
diag::specialize_attr_nongeneric_trailing_where, FD->getName())
1645+
diag::specialize_attr_nongeneric_trailing_where,
1646+
FD->getFullName())
16461647
.highlight(trailingWhereClause->getSourceRange());
16471648
return;
16481649
}
@@ -1823,7 +1824,7 @@ void AttributeChecker::visitFixedLayoutAttr(FixedLayoutAttr *attr) {
18231824
if (access < Accessibility::Public) {
18241825
TC.diagnose(attr->getLocation(),
18251826
diag::fixed_layout_attr_on_internal_type,
1826-
VD->getBaseName(),
1827+
VD->getFullName(),
18271828
access)
18281829
.fixItRemove(attr->getRangeWithAt());
18291830
attr->setInvalid();
@@ -1847,7 +1848,7 @@ void AttributeChecker::visitVersionedAttr(VersionedAttr *attr) {
18471848
if (VD->getFormalAccess() != Accessibility::Internal) {
18481849
TC.diagnose(attr->getLocation(),
18491850
diag::versioned_attr_with_explicit_accessibility,
1850-
VD->getBaseName(),
1851+
VD->getFullName(),
18511852
VD->getFormalAccess())
18521853
.fixItRemove(attr->getRangeWithAt());
18531854
attr->setInvalid();

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4330,7 +4330,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
43304330
TC.diagnose(NTD->getLoc(),
43314331
diag::unsupported_type_nested_in_generic_function,
43324332
NTD->getName(),
4333-
AFD->getName());
4333+
AFD->getFullName());
43344334
} else {
43354335
TC.diagnose(NTD->getLoc(),
43364336
diag::unsupported_type_nested_in_generic_closure,

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func rdar21080030() {
167167
}
168168

169169
// <rdar://problem/21248136> QoI: problem with return type inference mis-diagnosed as invalid arguments
170-
func r21248136<T>() -> T { preconditionFailure() } // expected-note 2 {{in call to function 'r21248136'}}
170+
func r21248136<T>() -> T { preconditionFailure() } // expected-note 2 {{in call to function 'r21248136()'}}
171171

172172
r21248136() // expected-error {{generic parameter 'T' could not be inferred}}
173173
let _ = r21248136() // expected-error {{generic parameter 'T' could not be inferred}}

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ var _ : Int = R24267414.foo() // expected-error {{generic parameter 'T' could no
205205

206206

207207
// https://bugs.swift.org/browse/SR-599
208-
func SR599<T: FixedWidthInteger>() -> T.Type { return T.self } // expected-note {{in call to function 'SR599'}}
208+
func SR599<T: FixedWidthInteger>() -> T.Type { return T.self } // expected-note {{in call to function 'SR599()'}}
209209
_ = SR599() // expected-error {{generic parameter 'T' could not be inferred}}
210210

211211

test/Generics/materializable_restrictions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func test20807269() {
1515
func test15921530() {
1616
struct X {}
1717

18-
func makef<T>() -> (T) -> () { // expected-note {{in call to function 'makef'}}
18+
func makef<T>() -> (T) -> () { // expected-note {{in call to function 'makef()'}}
1919
return {
2020
x in ()
2121
}

test/Generics/unbound.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SomeClassWithInvalidMethod {
5959
// <rdar://problem/20792596> QoI: Cannot invoke with argument list (T), expected an argument list of (T)
6060
protocol r20792596P {}
6161

62-
// expected-note @+1 {{in call to function 'foor20792596'}}
62+
// expected-note @+1 {{in call to function 'foor20792596(x:)'}}
6363
func foor20792596<T: r20792596P>(x: T) -> T {
6464
return x
6565
}

test/attr/attr_specialize.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public func twoGenericParams<T, U>(_ t: T, u: U) -> (T, U) {
3939
return (t, u)
4040
}
4141

42-
@_specialize(where T == Int) // expected-error{{trailing 'where' clause in '_specialize' attribute of non-generic function 'nonGenericParam'}}
42+
@_specialize(where T == Int) // expected-error{{trailing 'where' clause in '_specialize' attribute of non-generic function 'nonGenericParam(x:)'}}
4343
func nonGenericParam(x: Int) {}
4444

4545
// Specialize contextual types.
@@ -94,7 +94,7 @@ func sameTypeRequirement<T : HasElt>(_ t: T) where T.Element == Float {}
9494
@_specialize(where T == NonSub) // expected-error{{'T' requires that 'NonSub' inherit from 'Base'}}
9595
func superTypeRequirement<T : Base>(_ t: T) {}
9696

97-
@_specialize(where X:_Trivial(8), Y == Int) // expected-error{{trailing 'where' clause in '_specialize' attribute of non-generic function 'requirementOnNonGenericFunction'}}
97+
@_specialize(where X:_Trivial(8), Y == Int) // expected-error{{trailing 'where' clause in '_specialize' attribute of non-generic function 'requirementOnNonGenericFunction(x:y:)'}}
9898
public func requirementOnNonGenericFunction(x: Int, y: Int) {
9999
}
100100

test/attr/attr_versioned.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// RUN: %target-typecheck-verify-swift -enable-testing
33

44
@_versioned private func privateVersioned() {}
5-
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'privateVersioned' is private}}
5+
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'privateVersioned()' is private}}
66

77
@_versioned fileprivate func fileprivateVersioned() {}
8-
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'fileprivateVersioned' is fileprivate}}
8+
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'fileprivateVersioned()' is fileprivate}}
99

1010
@_versioned internal func internalVersioned() {}
1111
// OK
@@ -14,11 +14,11 @@
1414
// OK
1515

1616
@_versioned public func publicVersioned() {}
17-
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'publicVersioned' is public}}
17+
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'publicVersioned()' is public}}
1818

1919
internal class internalClass {
2020
@_versioned public func publicVersioned() {}
21-
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'publicVersioned' is public}}
21+
// expected-error@-1 {{'@_versioned' attribute can only be applied to internal declarations, but 'publicVersioned()' is public}}
2222
}
2323

2424
fileprivate class filePrivateClass {

test/decl/inherit/initializer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ class SubVariadic : SuperVariadic { } // expected-warning 4{{synthesizing a vari
145145
// Don't crash with invalid nesting of class in generic function
146146

147147
func testClassInGenericFunc<T>(t: T) {
148-
class A { init(t: T) {} } // expected-error {{type 'A' cannot be nested in generic function 'testClassInGenericFunc'}}
149-
class B : A {} // expected-error {{type 'B' cannot be nested in generic function 'testClassInGenericFunc'}}
148+
class A { init(t: T) {} } // expected-error {{type 'A' cannot be nested in generic function 'testClassInGenericFunc(t:)'}}
149+
class B : A {} // expected-error {{type 'B' cannot be nested in generic function 'testClassInGenericFunc(t:)'}}
150150

151151
_ = B(t: t)
152152
}

test/decl/nested/type_in_function.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class OuterGenericClass<T> {
9696

9797
// Name lookup within local classes.
9898
func f5<T, U>(x: T, y: U) {
99-
struct Local { // expected-error {{type 'Local' cannot be nested in generic function 'f5'}}
99+
struct Local { // expected-error {{type 'Local' cannot be nested in generic function 'f5(x:y:)'}}
100100
func f() {
101101
_ = 17 as T // expected-error{{'Int' is not convertible to 'T'}} {{14-16=as!}}
102102
_ = 17 as U // okay: refers to 'U' declared within the local class
@@ -110,15 +110,15 @@ struct OuterGenericStruct<A> {
110110
class MiddleNonGenericClass {
111111
func nonGenericFunction() {
112112
class InnerGenericClass<T> : MiddleNonGenericClass {
113-
// expected-error@-1 {{type 'InnerGenericClass' cannot be nested in generic function 'nonGenericFunction'}}
113+
// expected-error@-1 {{type 'InnerGenericClass' cannot be nested in generic function 'nonGenericFunction()'}}
114114
override init() { super.init() }
115115
}
116116
}
117117
}
118118

119119
func middleFunction() {
120120
struct ConformingType : Racoon {
121-
// expected-error@-1 {{type 'ConformingType' cannot be nested in generic function 'middleFunction'}}
121+
// expected-error@-1 {{type 'ConformingType' cannot be nested in generic function 'middleFunction()'}}
122122
typealias Stripes = A
123123
}
124124
}
@@ -127,9 +127,9 @@ struct OuterGenericStruct<A> {
127127
// Issue with diagnoseUnknownType().
128128
func genericFunction<T>(t: T) {
129129
class First : Second<T>.UnknownType { }
130-
// expected-error@-1 {{type 'First' cannot be nested in generic function 'genericFunction'}}
130+
// expected-error@-1 {{type 'First' cannot be nested in generic function 'genericFunction(t:)'}}
131131
class Second<T> : Second { }
132-
// expected-error@-1 {{type 'Second' cannot be nested in generic function 'genericFunction'}}
132+
// expected-error@-1 {{type 'Second' cannot be nested in generic function 'genericFunction(t:)'}}
133133
// expected-error@-2 2 {{circular class inheritance Second}}
134134
}
135135

0 commit comments

Comments
 (0)