File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -5683,11 +5683,16 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
5683
5683
if (AD->isGetter () && !AD->getAccessorKeywordLoc ().isValid ())
5684
5684
return ;
5685
5685
}
5686
-
5686
+
5687
5687
auto &d = getASTContext ().Diags ;
5688
- d.diagnose (FD->getFuncLoc (), diag::change_to_mutating,
5689
- isa<AccessorDecl>(FD))
5690
- .fixItInsert (FD->getFuncLoc (), " mutating " );
5688
+ auto diags = d.diagnose (FD->getFuncLoc (), diag::change_to_mutating,
5689
+ isa<AccessorDecl>(FD));
5690
+ if (auto nonmutatingAttr =
5691
+ FD->getAttrs ().getAttribute <NonMutatingAttr>()) {
5692
+ diags.fixItReplace (nonmutatingAttr->getLocation (), " mutating " );
5693
+ } else {
5694
+ diags.fixItInsert (FD->getFuncLoc (), " mutating " );
5695
+ }
5691
5696
return ;
5692
5697
}
5693
5698
}
Original file line number Diff line number Diff line change @@ -681,3 +681,23 @@ struct SS {
681
681
j = j // expected-error {{cannot assign to value: 'j' is a 'let' constant}}
682
682
}
683
683
}
684
+
685
+ protocol JustAProtocol {
686
+ var name : String { get set }
687
+ }
688
+
689
+ extension JustAProtocol {
690
+ var foo : String {
691
+ get { return name }
692
+ nonmutating set { name = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
693
+ // expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-16=mutating}}
694
+ }
695
+
696
+ nonmutating func bar( ) { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{3-14=mutating}}
697
+ name = " Hello " // expected-error {{cannot assign to property: 'self' is immutable}}
698
+ }
699
+
700
+ func baz( ) { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{3-3=mutating }}
701
+ name = " World " // expected-error {{cannot assign to property: 'self' is immutable}}
702
+ }
703
+ }
You can’t perform that action at this time.
0 commit comments