From 9cbe151e955625a8d104041e40d0543ecb59dca8 Mon Sep 17 00:00:00 2001 From: David Zarzycki Date: Sun, 2 Feb 2020 06:57:05 -0500 Subject: [PATCH] [AST] NFC: Deconflate mutation of self and InOut params --- lib/AST/ASTContext.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a5d494d2805df..6194a8994faba 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2429,10 +2429,8 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD, isDynamicSelf = true; } else if (auto *CD = dyn_cast(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; @@ -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) @@ -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.