Sema: Make implicit elementwise struct init insensitive to lazy validation order.

With batch mode, other files may have forced lazy properties to get finalized before the implicit constructor is formed. Avoid the order dependency by making the behavior stable regardless of the type-checking phase of lazy declarations. Fixes rdar://problem/40903186.
This commit is contained in:
Joe Groff
2018-06-13 15:01:36 -07:00
parent b52ef8b4d0
commit da591acbca
3 changed files with 24 additions and 4 deletions

View File

@@ -1881,12 +1881,21 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
if (ICK == ImplicitConstructorKind::Memberwise) {
assert(isa<StructDecl>(decl) && "Only struct have memberwise constructor");
// Computed and static properties are not initialized.
for (auto var : decl->getStoredProperties()) {
if (var->isImplicit())
for (auto member : decl->getMembers()) {
auto var = dyn_cast<VarDecl>(member);
if (!var)
continue;
// Implicit, computed, and static properties are not initialized.
// The exception is lazy properties, which due to batch mode we may or
// may not have yet finalized, so they may currently be "stored" or
// "computed" in the current AST state.
if (var->isImplicit() || var->isStatic())
continue;
tc.validateDecl(var);
if (!var->hasStorage() && !var->getAttrs().hasAttribute<LazyAttr>())
continue;
// Initialized 'let' properties have storage, but don't get an argument
// to the memberwise initializer since they already have an initial
// value that cannot be overridden.