From da3155249b1c1c74ed6eb694fea4a4a02c5c6de0 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Mon, 18 Mar 2019 13:02:27 -0700 Subject: [PATCH] Sema: Don't add dynamic to defer bodies --- lib/Sema/TypeCheckAttr.cpp | 6 ++++++ test/SILGen/dynamically_replaceable.swift | 6 ++++++ 2 files changed, 12 insertions(+) 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 +}