@@ -8686,27 +8686,30 @@ static DefaultArgumentKind computeDefaultArgumentKind(DeclContext *dc,
86868686 llvm_unreachable (" Unhandled MagicIdentifierLiteralExpr in switch." );
86878687}
86888688
8689- ParamDecl *ParamDecl::createParsed (ASTContext &Context, SourceLoc specifierLoc,
8690- SourceLoc argumentNameLoc,
8691- Identifier argumentName,
8692- SourceLoc parameterNameLoc,
8693- Identifier parameterName, Expr *defaultValue,
8694- DeclContext *dc) {
8689+ ParamDecl *ParamDecl::createParsed (
8690+ ASTContext &Context, SourceLoc specifierLoc, SourceLoc argumentNameLoc,
8691+ Identifier argumentName, SourceLoc parameterNameLoc,
8692+ Identifier parameterName, Expr *defaultValue,
8693+ DefaultArgumentInitializer *defaultValueInitContext, DeclContext *dc) {
86958694 auto *decl =
86968695 new (Context) ParamDecl (specifierLoc, argumentNameLoc, argumentName,
86978696 parameterNameLoc, parameterName, dc);
86988697
8699- const auto kind = computeDefaultArgumentKind (dc, defaultValue);
8700- if (kind == DefaultArgumentKind::Inherited) {
8701- // The 'super' in inherited default arguments is a specifier rather than an
8702- // expression.
8703- // TODO: However, we may want to retain its location for diagnostics.
8704- defaultValue = nullptr ;
8698+ if (defaultValue) {
8699+ const auto kind = computeDefaultArgumentKind (dc, defaultValue);
8700+ if (kind == DefaultArgumentKind::Inherited) {
8701+ // The 'super' in inherited default arguments is a specifier rather than
8702+ // an expression.
8703+ // TODO: However, we may want to retain its location for diagnostics.
8704+ defaultValue = nullptr ;
8705+ }
8706+ ASSERT (defaultValueInitContext);
8707+ decl->setDefaultExpr (defaultValue);
8708+ decl->setDefaultArgumentKind (kind);
8709+ if (defaultValue)
8710+ decl->setDefaultArgumentInitContext (defaultValueInitContext);
87058711 }
87068712
8707- decl->setDefaultExpr (defaultValue);
8708- decl->setDefaultArgumentKind (kind);
8709-
87108713 return decl;
87118714}
87128715
@@ -8870,7 +8873,7 @@ AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
88708873 return AnyFunctionType::Param (type, label, flags, internalLabel);
88718874}
88728875
8873- std::optional<Initializer *>
8876+ std::optional<DefaultArgumentInitializer *>
88748877ParamDecl::getCachedDefaultArgumentInitContext () const {
88758878 if (auto *defaultInfo = DefaultValueAndFlags.getPointer ())
88768879 if (auto *init = defaultInfo->InitContextAndIsTypeChecked .getPointer ())
@@ -9043,7 +9046,8 @@ CustomAttr *ValueDecl::getAttachedResultBuilder() const {
90439046 nullptr );
90449047}
90459048
9046- void ParamDecl::setDefaultArgumentInitContext (Initializer *initContext) {
9049+ void ParamDecl::setDefaultArgumentInitContext (
9050+ DefaultArgumentInitializer *initContext) {
90479051 auto oldContext = getCachedDefaultArgumentInitContext ();
90489052 assert ((!oldContext || oldContext == initContext) &&
90499053 " Cannot change init context after setting" );
@@ -9246,15 +9250,9 @@ ParamDecl::setDefaultValueStringRepresentation(StringRef stringRepresentation) {
92469250 stringRepresentation;
92479251}
92489252
9249- void DefaultArgumentInitializer::changeFunction (
9250- DeclContext *parent, ParameterList *paramList) {
9251- if (parent->isLocalContext ()) {
9252- setParent (parent);
9253- }
9254-
9255- auto param = paramList->get (getIndex ());
9256- if (param->hasDefaultExpr () || param->getStoredProperty ())
9257- param->setDefaultArgumentInitContext (this );
9253+ void DefaultArgumentInitializer::changeFunction (DeclContext *parent) {
9254+ ASSERT (parent->isLocalContext ());
9255+ setParent (parent);
92589256}
92599257
92609258// / Determine whether the given Swift type is an integral type, i.e.,
0 commit comments