mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema] PreCheck: Diagnose standalone self within init accessors
'self' within init accessor could only be used to refer to properties listed in `initializes` and `accesses` attributes.
This commit is contained in:
@@ -82,6 +82,7 @@ namespace swift {
|
||||
class SerializedDefaultArgumentInitializer;
|
||||
class SerializedTopLevelCodeDecl;
|
||||
class StructDecl;
|
||||
class AccessorDecl;
|
||||
|
||||
namespace serialization {
|
||||
using DeclID = llvm::PointerEmbeddedInt<unsigned, 31>;
|
||||
@@ -457,6 +458,18 @@ public:
|
||||
return const_cast<DeclContext*>(this)->getInnermostMethodContext();
|
||||
}
|
||||
|
||||
/// Returns the innermost accessor context that belongs to a property.
|
||||
///
|
||||
/// This routine looks through closure, initializer, and local function
|
||||
/// contexts to find the innermost accessor declaration.
|
||||
///
|
||||
/// \returns the innermost accessor, or null if there is no such context.
|
||||
LLVM_READONLY
|
||||
AccessorDecl *getInnermostPropertyAccessorContext();
|
||||
const AccessorDecl *getInnermostPropertyAccessorContext() const {
|
||||
return const_cast<DeclContext*>(this)->getInnermostPropertyAccessorContext();
|
||||
}
|
||||
|
||||
/// Returns the innermost type context.
|
||||
///
|
||||
/// This routine looks through closure, initializer, and local function
|
||||
|
||||
@@ -7342,6 +7342,10 @@ ERROR(init_accessor_accesses_attribute_on_other_declaration,none,
|
||||
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 "
|
||||
"properties listed in 'initializes' and 'accesses'; "
|
||||
"init accessors are run before 'self' is fully available", ())
|
||||
|
||||
|
||||
#define UNDEFINE_DIAGNOSTIC_MACROS
|
||||
|
||||
Reference in New Issue
Block a user