diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 6c6fa7edad101..532a1631601f6 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -2566,6 +2566,12 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) { D->getAttrs().hasAttribute()) return; + if (auto *FD = dyn_cast(D)) { + // Don't add dynamic to defer bodies. + if (FD->isDeferBody()) + return; + } + if (auto *VD = dyn_cast(D)) { // Don't turn stored into computed properties. This could conflict with // exclusivity checking. diff --git a/test/SILGen/dynamically_replaceable.swift b/test/SILGen/dynamically_replaceable.swift index 714375767ce66..1aa58dae1a93f 100644 --- a/test/SILGen/dynamically_replaceable.swift +++ b/test/SILGen/dynamically_replaceable.swift @@ -356,3 +356,9 @@ func getsetX(_ x: Int) -> Int { dynamic func funcWithDefaultArg(_ arg : String = String("hello")) { print("hello") } + +// IMPLICIT-LABEL: sil private [ossa] @$s23dynamically_replaceable6$deferL_yyF +var x = 10 +defer { + let y = x +}