@@ -8685,27 +8685,30 @@ static DefaultArgumentKind computeDefaultArgumentKind(DeclContext *dc,
86858685 llvm_unreachable (" Unhandled MagicIdentifierLiteralExpr in switch." );
86868686}
86878687
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) {
86948693 auto *decl =
86958694 new (Context) ParamDecl (specifierLoc, argumentNameLoc, argumentName,
86968695 parameterNameLoc, parameterName, dc);
86978696
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);
87048710 }
87058711
8706- decl->setDefaultExpr (defaultValue);
8707- decl->setDefaultArgumentKind (kind);
8708-
87098712 return decl;
87108713}
87118714
@@ -8869,7 +8872,7 @@ AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
88698872 return AnyFunctionType::Param (type, label, flags, internalLabel);
88708873}
88718874
8872- std::optional<Initializer *>
8875+ std::optional<DefaultArgumentInitializer *>
88738876ParamDecl::getCachedDefaultArgumentInitContext () const {
88748877 if (auto *defaultInfo = DefaultValueAndFlags.getPointer ())
88758878 if (auto *init = defaultInfo->InitContextAndIsTypeChecked .getPointer ())
@@ -9042,7 +9045,8 @@ CustomAttr *ValueDecl::getAttachedResultBuilder() const {
90429045 nullptr );
90439046}
90449047
9045- void ParamDecl::setDefaultArgumentInitContext (Initializer *initContext) {
9048+ void ParamDecl::setDefaultArgumentInitContext (
9049+ DefaultArgumentInitializer *initContext) {
90469050 auto oldContext = getCachedDefaultArgumentInitContext ();
90479051 assert ((!oldContext || oldContext == initContext) &&
90489052 " Cannot change init context after setting" );
@@ -9245,15 +9249,9 @@ ParamDecl::setDefaultValueStringRepresentation(StringRef stringRepresentation) {
92459249 stringRepresentation;
92469250}
92479251
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);
92579255}
92589256
92599257// / Determine whether the given Swift type is an integral type, i.e.,
0 commit comments