@@ -8685,27 +8685,30 @@ static DefaultArgumentKind computeDefaultArgumentKind(DeclContext *dc,
8685
8685
llvm_unreachable (" Unhandled MagicIdentifierLiteralExpr in switch." );
8686
8686
}
8687
8687
8688
- ParamDecl *ParamDecl::createParsed (ASTContext &Context, SourceLoc specifierLoc,
8689
- SourceLoc argumentNameLoc,
8690
- Identifier argumentName,
8691
- SourceLoc parameterNameLoc,
8692
- Identifier parameterName, Expr *defaultValue,
8693
- DeclContext *dc) {
8688
+ ParamDecl *ParamDecl::createParsed (
8689
+ ASTContext &Context, SourceLoc specifierLoc, SourceLoc argumentNameLoc,
8690
+ Identifier argumentName, SourceLoc parameterNameLoc,
8691
+ Identifier parameterName, Expr *defaultValue,
8692
+ DefaultArgumentInitializer *defaultValueInitContext, DeclContext *dc) {
8694
8693
auto *decl =
8695
8694
new (Context) ParamDecl (specifierLoc, argumentNameLoc, argumentName,
8696
8695
parameterNameLoc, parameterName, dc);
8697
8696
8698
- const auto kind = computeDefaultArgumentKind (dc, defaultValue);
8699
- if (kind == DefaultArgumentKind::Inherited) {
8700
- // The 'super' in inherited default arguments is a specifier rather than an
8701
- // expression.
8702
- // TODO: However, we may want to retain its location for diagnostics.
8703
- defaultValue = nullptr ;
8697
+ if (defaultValue) {
8698
+ const auto kind = computeDefaultArgumentKind (dc, defaultValue);
8699
+ if (kind == DefaultArgumentKind::Inherited) {
8700
+ // The 'super' in inherited default arguments is a specifier rather than
8701
+ // an expression.
8702
+ // TODO: However, we may want to retain its location for diagnostics.
8703
+ defaultValue = nullptr ;
8704
+ }
8705
+ ASSERT (defaultValueInitContext);
8706
+ decl->setDefaultExpr (defaultValue);
8707
+ decl->setDefaultArgumentKind (kind);
8708
+ if (defaultValue)
8709
+ decl->setDefaultArgumentInitContext (defaultValueInitContext);
8704
8710
}
8705
8711
8706
- decl->setDefaultExpr (defaultValue);
8707
- decl->setDefaultArgumentKind (kind);
8708
-
8709
8712
return decl;
8710
8713
}
8711
8714
@@ -8869,7 +8872,7 @@ AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
8869
8872
return AnyFunctionType::Param (type, label, flags, internalLabel);
8870
8873
}
8871
8874
8872
- std::optional<Initializer *>
8875
+ std::optional<DefaultArgumentInitializer *>
8873
8876
ParamDecl::getCachedDefaultArgumentInitContext () const {
8874
8877
if (auto *defaultInfo = DefaultValueAndFlags.getPointer ())
8875
8878
if (auto *init = defaultInfo->InitContextAndIsTypeChecked .getPointer ())
@@ -9042,7 +9045,8 @@ CustomAttr *ValueDecl::getAttachedResultBuilder() const {
9042
9045
nullptr );
9043
9046
}
9044
9047
9045
- void ParamDecl::setDefaultArgumentInitContext (Initializer *initContext) {
9048
+ void ParamDecl::setDefaultArgumentInitContext (
9049
+ DefaultArgumentInitializer *initContext) {
9046
9050
auto oldContext = getCachedDefaultArgumentInitContext ();
9047
9051
assert ((!oldContext || oldContext == initContext) &&
9048
9052
" Cannot change init context after setting" );
@@ -9245,15 +9249,9 @@ ParamDecl::setDefaultValueStringRepresentation(StringRef stringRepresentation) {
9245
9249
stringRepresentation;
9246
9250
}
9247
9251
9248
- void DefaultArgumentInitializer::changeFunction (
9249
- DeclContext *parent, ParameterList *paramList) {
9250
- if (parent->isLocalContext ()) {
9251
- setParent (parent);
9252
- }
9253
-
9254
- auto param = paramList->get (getIndex ());
9255
- if (param->hasDefaultExpr () || param->getStoredProperty ())
9256
- param->setDefaultArgumentInitContext (this );
9252
+ void DefaultArgumentInitializer::changeFunction (DeclContext *parent) {
9253
+ ASSERT (parent->isLocalContext ());
9254
+ setParent (parent);
9257
9255
}
9258
9256
9259
9257
// / Determine whether the given Swift type is an integral type, i.e.,
0 commit comments