ParamDecl: Defend against default argument kind overwrites

This commit is contained in:
Anthony Latsis
2023-12-23 00:08:33 +03:00
parent 516efdf43f
commit fa6924a34e
3 changed files with 43 additions and 25 deletions

View File

@@ -8253,13 +8253,19 @@ ParamDecl::ParamDecl(SourceLoc specifierLoc, SourceLoc argumentNameLoc,
static_cast<unsigned>(DefaultArgumentKind::None);
}
ParamDecl *ParamDecl::cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD) {
ParamDecl *
ParamDecl::cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD,
std::optional<DefaultArgumentKind> defaultArgKind) {
auto *Clone = new (Ctx) ParamDecl(
SourceLoc(), SourceLoc(), PD->getArgumentName(),
SourceLoc(), PD->getParameterName(), PD->getDeclContext());
Clone->setOptionsAndPointers(nullptr, nullptr, PD->getOptions());
Clone->Bits.ParamDecl.defaultArgumentKind =
PD->Bits.ParamDecl.defaultArgumentKind;
if (defaultArgKind) {
Clone->setDefaultArgumentKind(*defaultArgKind);
} else {
Clone->setDefaultArgumentKind(PD->getDefaultArgumentKind());
}
Clone->setSpecifier(PD->getSpecifier());
Clone->setImplicitlyUnwrappedOptional(PD->isImplicitlyUnwrappedOptional());
@@ -8367,6 +8373,12 @@ ParamDecl *ParamDecl::createParsed(ASTContext &Context, SourceLoc specifierLoc,
return decl;
}
void ParamDecl::setDefaultArgumentKind(DefaultArgumentKind K) {
assert(getDefaultArgumentKind() == DefaultArgumentKind::None &&
"Overwrite of default argument kind");
Bits.ParamDecl.defaultArgumentKind = static_cast<unsigned>(K);
}
/// Retrieve the type of 'self' for the given context.
Type DeclContext::getSelfTypeInContext() const {
return mapTypeIntoContext(getSelfInterfaceType());