Skip to content

Commit e8b9b8c

Browse files
committed
fix static_functions_not_mutating error msg
1 parent 80050bb commit e8b9b8c

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,10 @@ ERROR(functions_mutating_and_not,none,
17351735
"method must not be declared both %0 and %1",
17361736
(SelfAccessKind, SelfAccessKind))
17371737
ERROR(static_functions_not_mutating,none,
1738-
"static functions must not be declared mutating", ())
1738+
"%0 modifier cannot be used on static functions",
1739+
(SelfAccessKind))
1740+
NOTE(static_functions_not_mutating_detail,none,
1741+
"static members cannot access instance properties or self", ())
17391742

17401743
ERROR(readwriter_mutatingness_differs_from_reader_or_writer_mutatingness,none,
17411744
"%0 cannot be %1 when "

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,10 @@ void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
785785
}
786786
}
787787
// Verify that we don't have a static function.
788-
if (FD->isStatic())
789-
diagnoseAndRemoveAttr(attr, diag::static_functions_not_mutating);
788+
if (FD->isStatic()) {
789+
diagnoseAndRemoveAttr(attr, diag::static_functions_not_mutating, attrModifier);
790+
diagnose(FD, diag::static_functions_not_mutating_detail);
791+
}
790792
}
791793

792794
void AttributeChecker::visitDynamicAttr(DynamicAttr *attr) {

test/Sema/immutability.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ struct SomeStruct {
131131

132132
static let type_let = 5 // expected-note {{change 'let' to 'var' to make it mutable}} {{10-13=var}}
133133

134-
mutating static func f() { // expected-error {{static functions must not be declared mutating}} {{3-12=}}
134+
mutating static func f() { // expected-error {{'mutating' modifier cannot be used on static functions}} {{3-12=}}
135+
// expected-note@-1 {{static members cannot access instance properties or self}}
135136
}
136137

137138
mutating func g() {

test/decl/overload.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ protocol ProtocolWithMutating {
410410
mutating func test2(_ a: Int?) // expected-note {{previously declared}}
411411
func test2(_ a: Int!) // expected-error{{invalid redeclaration of 'test2'}}
412412

413-
mutating static func classTest1() // expected-error {{static functions must not be declared mutating}} {{3-12=}} expected-note {{previously declared}}
413+
mutating static func classTest1() // expected-error {{'mutating' modifier cannot be used on static functions}} {{3-12=}} expected-note {{previously declared}}
414+
// expected-note@-1 {{static members cannot access instance properties or self}}
414415
static func classTest1() // expected-error{{invalid redeclaration of 'classTest1()'}}
415416
}
416417

test/decl/subscript/static.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ func useMyStruct() {
2020

2121
struct BadStruct {
2222
static subscript(_ i: Int) -> String {
23-
nonmutating get { fatalError() } // expected-error{{static functions must not be declared mutating}}
24-
mutating set { fatalError() } // expected-error{{static functions must not be declared mutating}}
23+
nonmutating get { fatalError() } // expected-error {{'nonmutating' modifier cannot be used on static functions}}
24+
// expected-note@-1 {{static members cannot access instance properties or self}}
25+
mutating set { fatalError() } // expected-error {{'mutating' modifier cannot be used on static functions}}
26+
// expected-note@-1 {{static members cannot access instance properties or self}}
2527
}
2628
}
2729

0 commit comments

Comments
 (0)