Skip to content

Commit ba25dc3

Browse files
Merge pull request #23446 from aschwaighofer/defer_body_not_dynamic-5.1
Sema: Don't add dynamic to defer bodies
2 parents 7c96888 + 4f6d9fb commit ba25dc3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,12 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
25662566
D->getAttrs().hasAttribute<InlinableAttr>())
25672567
return;
25682568

2569+
if (auto *FD = dyn_cast<FuncDecl>(D)) {
2570+
// Don't add dynamic to defer bodies.
2571+
if (FD->isDeferBody())
2572+
return;
2573+
}
2574+
25692575
if (auto *VD = dyn_cast<VarDecl>(D)) {
25702576
// Don't turn stored into computed properties. This could conflict with
25712577
// exclusivity checking.

test/SILGen/dynamically_replaceable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,9 @@ func getsetX(_ x: Int) -> Int {
356356
dynamic func funcWithDefaultArg(_ arg : String = String("hello")) {
357357
print("hello")
358358
}
359+
360+
// IMPLICIT-LABEL: sil private [ossa] @$s23dynamically_replaceable6$deferL_yyF
361+
var x = 10
362+
defer {
363+
let y = x
364+
}

0 commit comments

Comments
 (0)