Skip to content

[6.0] AST: Fix request cycle with local lazy properties #74165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
9 changes: 9 additions & 0 deletions lib/AST/UnqualifiedLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ static bool implicitSelfReferenceIsUnwrapped(const ValueDecl *selfDecl) {
}

ValueDecl *UnqualifiedLookupFactory::lookupBaseDecl(const DeclContext *baseDC) const {
// If the member was not in local context, we're not going to need the
// 'self' declaration, so skip all this work to avoid request cycles.
if (!baseDC->isLocalContext())
return nullptr;

// If we're only interested in type declarations, we can also skip everything.
if (isOriginallyTypeLookup)
return nullptr;

// Perform an unqualified lookup for the base decl of this result. This
// handles cases where self was rebound (e.g. `guard let self = self`)
// earlier in this closure or some outer closure.
Expand Down
12 changes: 12 additions & 0 deletions test/decl/var/lazy_properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ struct PropertyWrapperContainer {
_ = $__lazy_storage_$_foo // This is okay.
}
}

// rdar://problem/129255769
struct X {
struct Y { }

func f() {
_ = {
lazy var x: [Y] = []
_ = Y()
}
}
}