Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3975,8 +3975,8 @@ ERROR(attr_incompatible_with_objc,none,
(DeclAttribute, DescriptiveDeclKind))

ERROR(final_not_on_accessors,none,
"'final' cannot be applied to accessors, it must be put on the "
"%select{var|let|subscript}0", (unsigned))
"'final' cannot be applied to %1, it must be put on the "
"%select{var|let|subscript}0", (unsigned, DescriptiveDeclKind))

ERROR(override_rethrows_with_non_rethrows,none,
"override of 'rethrows' %select{method|initializer}0 should also "
Expand Down Expand Up @@ -5010,8 +5010,8 @@ NOTE(candidate_is_not_assignable,none,
(const ValueDecl *))

NOTE(change_to_mutating,none,
"mark %select{method|accessor}0 'mutating' to make 'self' mutable",
(bool))
"mark %select{method|%1}0 'mutating' to make 'self' mutable",
(bool, StringRef))
NOTE(masked_mutable_property,none,
"add explicit '%0' to refer to mutable %1 of %2",
(StringRef, DescriptiveDeclKind, Type))
Expand Down Expand Up @@ -5857,7 +5857,7 @@ ERROR(distributed_property_can_only_be_computed,none,
"%kind0 cannot be 'distributed', only computed properties can",
(const ValueDecl *))
ERROR(distributed_property_accessor_only_get_can_be_distributed,none,
"only 'get' accessors may be 'distributed'",
"only getters may be 'distributed'",
())
NOTE(distributed_actor_isolated_property,none,
"access to %kind0 is only permitted within distributed actor %1",
Expand Down Expand Up @@ -6385,11 +6385,10 @@ NOTE(objc_witness_objc_requirement,none,
ERROR(no_opaque_return_type_of,none,
"unable to resolve type for _opaqueReturnTypeOf attribute", ())


ERROR(objc_observing_accessor, none,
"observing accessors are not allowed to be marked @objc", ())
"%0 is not allowed to be marked @objc", (DescriptiveDeclKind))
ERROR(objc_init_accessor, none,
"init accessors cannot be marked @objc", ())
"init functions cannot be marked @objc", ())
ERROR(objc_addressor, none,
"addressors are not allowed to be marked @objc", ())
ERROR(objc_coroutine_accessor, none,
Expand Down Expand Up @@ -6571,8 +6570,6 @@ ERROR(dynamic_with_transparent,none,
// MARK: @_dynamicReplacement(for:)
//------------------------------------------------------------------------------

ERROR(dynamic_replacement_accessor_type_mismatch, none,
"replaced accessor %0's type does not match", (DeclName))
ERROR(dynamic_replacement_accessor_not_dynamic, none,
"replaced accessor for %0 is not marked dynamic", (DeclName))
ERROR(dynamic_replacement_accessor_not_explicit, none,
Expand Down Expand Up @@ -7204,7 +7201,7 @@ ERROR(property_wrapper_computed, none,
"property wrapper cannot be applied to a computed property",
())
ERROR(property_wrapper_effectful,none,
"property wrappers currently cannot define an 'async' or 'throws' accessor",
"property wrappers currently cannot define an 'async' or 'throws'",
())

ERROR(property_with_wrapper_conflict_attribute,none,
Expand Down Expand Up @@ -7636,7 +7633,7 @@ ERROR(invalid_decl_in_macro_expansion,none,
"macro expansion cannot introduce %0",
(DescriptiveDeclKind))
ERROR(let_accessor_expansion,none,
"cannot expand accessors on variable declared with 'let'",
"cannot expand macros on variable declared with 'let'",
())
ERROR(invalid_main_type_in_macro_expansion,none,
"macro expansion cannot introduce '@main' type",
Expand All @@ -7656,14 +7653,13 @@ ERROR(invalid_macro_role_for_macro_syntax,none,
ERROR(macro_cannot_introduce_names,none,
"'%0' macros are not allowed to introduce names", (StringRef))
ERROR(macro_nonobserving_accessor_missing_from_expansion,none,
"expansion of macro %0 did not produce a non-observing accessor "
"(such as 'get') as expected",
"expansion of macro %0 did not produce a getter or a setter as expected",
(DeclName))
ERROR(macro_nonobserver_unexpected_in_expansion,none,
"expansion of macro %0 produced an unexpected %1",
(DeclName, DescriptiveDeclKind))
ERROR(macro_init_accessor_not_documented,none,
"expansion of macro %0 produced an unexpected 'init' accessor",
"expansion of macro %0 produced an unexpected 'init' member",
(DeclName))
ERROR(global_arbitrary_name,none,
"'%0' macros are not allowed to introduce arbitrary names "
Expand Down Expand Up @@ -7705,7 +7701,7 @@ NOTE(macro_expand_circular_reference_unnamed_through, none,
"circular reference expanding %0 macros", (StringRef))

ERROR(accessor_macro_not_single_var, none,
"accessor macro %0 can only apply to a single variable", (DeclName))
"macro %0 can only apply to a single variable", (DeclName))

//------------------------------------------------------------------------------
// MARK: Noncopyable Types Diagnostics
Expand Down Expand Up @@ -7870,7 +7866,7 @@ ERROR(noncopyable_types_cannot_be_resilient, none,
"supported",
(const ValueDecl *))
ERROR(noncopyable_cannot_have_read_set_accessor,none,
"noncopyable %select{variable|subscript}0 cannot provide a read and set accessor",
"noncopyable %select{variable|subscript}0 cannot provide a read and set member",
(unsigned))

ERROR(nonescapable_types_attr_disabled,none,
Expand All @@ -7881,30 +7877,30 @@ ERROR(nonescapable_types_attr_disabled,none,
//------------------------------------------------------------------------------

ERROR(init_accessor_can_refer_only_to_properties,none,
"init accessor cannot refer to %0 %1; init accessors can refer only"
"init function cannot refer to %0 %1; init functions can refer only"
" to stored properties",
(DescriptiveDeclKind, DeclNameRef))

ERROR(storage_restrictions_attribute_not_on_init_accessor,none,
"@storageRestrictions attribute could only be used with init accessors",
"@storageRestrictions attribute could only be used with init functions",
())
ERROR(init_accessor_property_both_init_and_accessed,none,
"property %0 cannot be both initialized and accessed",
(DeclName))
ERROR(invalid_use_of_self_in_init_accessor,none,
"'self' within init accessors can only be used to reference "
"'self' within init function can only be used to reference "
"properties listed in 'initializes' and 'accesses'; "
"init accessors are run before 'self' is fully available", ())
"init function are run before 'self' is fully available", ())
ERROR(init_accessor_invalid_member_ref,none,
"cannot reference instance member %0; init accessors can only "
"cannot reference instance member %0; init function can only "
"refer to instance properties listed in 'initializes' and "
"'accesses' attributes",
(DeclNameRef))
ERROR(cannot_synthesize_memberwise_due_to_property_init_order,none,
"cannot synthesize memberwise initializer",
())
NOTE(out_of_order_access_in_init_accessor,none,
"init accessor for %0 cannot access stored property %1 because it "
"init function for %0 cannot access stored property %1 because it "
"is called before %1 is initialized",
(Identifier, Identifier))

Expand Down
3 changes: 2 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8332,8 +8332,9 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
}

auto &d = getASTContext().Diags;
auto descriptiveKindName = Decl::getDescriptiveKindName(FD->getDescriptiveKind());
auto diags = d.diagnose(FD->getFuncLoc(), diag::change_to_mutating,
isa<AccessorDecl>(FD));
isa<AccessorDecl>(FD),descriptiveKindName);
if (auto nonmutatingAttr =
FD->getAttrs().getAttribute<NonMutatingAttr>()) {
diags.fixItReplace(nonmutatingAttr->getLocation(), "mutating");
Expand Down
10 changes: 7 additions & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,11 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
if (!checkObjCDeclContext(D))
error = diag::invalid_objc_decl_context;
else if (auto accessor = dyn_cast<AccessorDecl>(func))
if (!accessor->isGetterOrSetter())
error = diag::objc_observing_accessor;
if (!accessor->isGetterOrSetter()) {
diagnoseAndRemoveAttr(attr, diag::objc_observing_accessor, accessor->getDescriptiveKind()).limitBehavior(behavior);
reason.describe(D);
return;
}
} else if (isa<ConstructorDecl>(D) ||
isa<DestructorDecl>(D) ||
isa<SubscriptDecl>(D) ||
Expand Down Expand Up @@ -2500,7 +2503,8 @@ void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
unsigned Kind = 2;
if (auto *VD = dyn_cast<VarDecl>(accessor->getStorage()))
Kind = VD->isLet() ? 1 : 0;
diagnose(attr->getLocation(), diag::final_not_on_accessors, Kind)
diagnose(attr->getLocation(), diag::final_not_on_accessors,
Kind, accessor->getDescriptiveKind())
.fixItRemove(attr->getRange());
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ bool swift::isRepresentableInObjC(
// willSet/didSet implementations are never exposed to objc, they are
// always directly dispatched from the synthesized setter.
diagnoseAndRemoveAttr(accessor, Reason.getAttr(),
diag::objc_observing_accessor)
diag::objc_observing_accessor, accessor->getDescriptiveKind())
.limitBehavior(behavior);
Reason.describe(accessor);
return false;
Expand Down
4 changes: 2 additions & 2 deletions test/Macros/accessor_macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct HasStoredTests {

#if TEST_DIAGNOSTICS
@AddWillSetSneakily var y: Int = 0
// expected-error@-1{{expansion of macro 'AddWillSetSneakily()' did not produce a non-observing accessor (such as 'get') as expected}}
// expected-error@-1{{expansion of macro 'AddWillSetSneakily()' did not produce a getter or a setter as expected}}

@MakeComputedSneakily var z: Int = 0
// expected-error@-1{{expansion of macro 'MakeComputedSneakily()' produced an unexpected getter}}
Expand All @@ -171,6 +171,6 @@ macro addGetterMacro() =
#if TEST_DIAGNOSTICS
struct S {
@addGetterMacro let x: Int
// expected-warning@-1 {{cannot expand accessors on variable declared with 'let'; this is an error in the Swift 6 language mode}}
// expected-warning@-1 {{cannot expand macros on variable declared with 'let'; this is an error in the Swift 6 language mode}}
}
#endif
8 changes: 4 additions & 4 deletions test/Sema/immutability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct SomeStruct {

var p: Int {
// Getters default to non-mutating.
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{5-5=mutating }}
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}} {{5-5=mutating }}
iv = 37 // expected-error {{cannot assign to property: 'self' is immutable}}
return 42
}
Expand All @@ -168,13 +168,13 @@ struct SomeStruct {
return 42
}
nonmutating
set { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{-1:5-16=mutating}}
set { // expected-note {{mark setter 'mutating' to make 'self' mutable}} {{-1:5-16=mutating}}
iv = newValue // expected-error {{cannot assign to property: 'self' is immutable}}
}
}

var r : Int {
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{5-5=mutating }}
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}} {{5-5=mutating }}
iv = 37 // expected-error {{cannot assign to property: 'self' is immutable}}
return 42
}
Expand Down Expand Up @@ -708,7 +708,7 @@ extension JustAProtocol {
var foo: String {
get { return name }
nonmutating set { name = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
// expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-16=mutating}}
// expected-note@-1 {{mark setter 'mutating' to make 'self' mutable}}{{5-16=mutating}}
}

nonmutating func bar() { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{3-14=mutating}}
Expand Down
24 changes: 12 additions & 12 deletions test/Sema/moveonly_read_set_ban.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,57 @@ public struct NonCopyableS : ~Copyable {}
public enum NonCopyableE : ~Copyable {}

public struct S {
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
}

public class C {
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
}

public enum E {
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set member}}
_read { fatalError() }
set { fatalError() }
}
Expand Down
6 changes: 3 additions & 3 deletions test/attr/attr_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class subject_getterSetter1 {
}

var observingAccessorsVar1: Int = 0 {
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
@objc // expected-error {{willSet observer is not allowed to be marked @objc}} {{5-11=}}
willSet {
}
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
@objc // expected-error {{didSet observer is not allowed to be marked @objc}} {{5-11=}}
didSet {
}
}
Expand Down Expand Up @@ -2091,7 +2091,7 @@ class BadClass2 {
}

var prop3: Int {
@objc(setProperty:) // expected-error{{observing accessors are not allowed to be marked @objc}} {{5-25=}}
@objc(setProperty:) // expected-error{{didSet observer is not allowed to be marked @objc}} {{5-25=}}
didSet { }
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/decl/ext/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ extension DoesNotImposeClassReq_2 where Self : AnyObject {
var wrappingProperty1: String {
get { property }
set { property = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
// expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-5=mutating }}
// expected-note@-1 {{mark setter 'mutating' to make 'self' mutable}}{{5-5=mutating }}
}

var wrappingProperty2: String {
Expand Down
2 changes: 1 addition & 1 deletion test/decl/subscript/subscripting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ struct MutableComputedGetter {
struct MutableSubscriptInGetter {
var value: Int
subscript(index: Int) -> Int {
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}}
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}}
value = 5 // expected-error{{cannot assign to property: 'self' is immutable}}
return 5
}
Expand Down
2 changes: 1 addition & 1 deletion test/decl/var/effectful_property_wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Abstraction<T> {
init(_ initial : T) { self.value = initial }

var wrappedValue : T {
get throws { return value } // expected-error{{property wrappers currently cannot define an 'async' or 'throws' accessor}}
get throws { return value } // expected-error{{property wrappers currently cannot define an 'async' or 'throws'}}
}

// its OK to have effectful props that are not `wrappedValue`
Expand Down
Loading