mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Fix bug where lazy properties could become stored sometimes
If synthesizeWitnessAccessorsForStorage() got called on a lazy property before maybeAddAccessorsToVariable(), we would build it as a stored property instead. This count result in bogus diagnostics, assertions and bad runtime behavior. Fixes <https://bugs.swift.org/browse/SR-1825>.
This commit is contained in:
@@ -807,6 +807,9 @@ static bool doesStorageNeedSetter(AbstractStorageDecl *storage) {
|
||||
static void addTrivialAccessorsToStorage(AbstractStorageDecl *storage,
|
||||
TypeChecker &TC) {
|
||||
assert(!storage->hasAccessorFunctions() && "already has accessors?");
|
||||
assert(!storage->getAttrs().hasAttribute<LazyAttr>());
|
||||
assert(!storage->getAttrs().hasAttribute<NSManagedAttr>());
|
||||
|
||||
auto *DC = storage->getDeclContext();
|
||||
|
||||
// Create the getter.
|
||||
@@ -922,10 +925,7 @@ void TypeChecker::synthesizeWitnessAccessorsForStorage(
|
||||
// If the decl is stored, convert it to StoredWithTrivialAccessors
|
||||
// by synthesizing the full set of accessors.
|
||||
if (!storage->hasAccessorFunctions()) {
|
||||
if (storage->getAttrs().hasAttribute<NSManagedAttr>())
|
||||
convertNSManagedStoredVarToComputed(cast<VarDecl>(storage), *this);
|
||||
else
|
||||
addTrivialAccessorsToStorage(storage, *this);
|
||||
addTrivialAccessorsToStorage(storage, *this);
|
||||
|
||||
if (auto getter = storage->getGetter())
|
||||
validateDecl(getter);
|
||||
|
||||
Reference in New Issue
Block a user