mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ParamDecl: Defend against default argument kind overwrites
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user