Ensure that we wire up *all* custom attribute initializer contexts

Thank you again, Rintaro
This commit is contained in:
Doug Gregor
2024-12-06 22:47:00 -08:00
parent 02a20ded57
commit d004d24560
5 changed files with 16 additions and 28 deletions

View File

@@ -8580,20 +8580,12 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
// Parse an initializer if present.
if (Tok.is(tok::equal)) {
// If we're not in a local context, we'll need a context to parse initializers
// into (should we have one). This happens for properties and global
// variables in libraries.
// If we have no local context to parse the initial value into, create one
// for the PBD we'll eventually create. This allows us to have reasonable
// DeclContexts for any closures that may live inside of initializers.
if (!CurDeclContext->isLocalContext() && !topLevelDecl) {
assert(!initContext && "There cannot be an init context yet");
initContext = PatternBindingInitializer::create(CurDeclContext);
if (auto attributeInit = Attributes.findCustomAttributeInitializer()) {
attributeInit->setEnclosingInitializer(initContext);
}
}
// If we're using a local context (either a TopLevelCodeDecl or a