Skip to content

[AST] NFC: Deconflate mutation of self and InOut params #29597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,10 +2429,8 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
isDynamicSelf = true;
} else if (auto *CD = dyn_cast<ConstructorDecl>(AFD)) {
if (isInitializingCtor) {
// initializing constructors of value types always have an implicitly
// inout self.
if (!containerTy->hasReferenceSemantics())
selfAccess = SelfAccessKind::Mutating;
// Initializing constructors are implicitly mutating.
selfAccess = SelfAccessKind::Mutating;
} else {
// allocating constructors have metatype 'self'.
isStatic = true;
Expand All @@ -2451,6 +2449,9 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
// Note that we can't assert(containerTy->hasReferenceSemantics()) here
// since incorrect or incomplete code could have deinit decls in invalid
// contexts, and we need to recover gracefully in those cases.

// Destructors are implicitly mutating.
selfAccess = SelfAccessKind::Mutating;
}

if (isDynamicSelf)
Expand All @@ -2466,7 +2467,7 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
flags = flags.withOwned(true);
break;
case SelfAccessKind::Mutating:
flags = flags.withInOut(true);
flags = flags.withInOut(!containerTy->hasReferenceSemantics());
break;
case SelfAccessKind::NonMutating:
// The default flagless state.
Expand Down