Skip to content

Commit 77ab34f

Browse files
Merge pull request #25072 from aschwaighofer/local_functions_not_implicit_dynamic-5.1
[5.1] Don't add implicit dynamic to local functions.
2 parents 5491c4e + fa0d8be commit 77ab34f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,10 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
26372637
// Don't add dynamic to functions with a cdecl.
26382638
if (FD->getAttrs().hasAttribute<CDeclAttr>())
26392639
return;
2640+
// Don't add dynamic to local function definitions.
2641+
if (!FD->getDeclContext()->isTypeContext() &&
2642+
FD->getDeclContext()->isLocalContext())
2643+
return;
26402644
}
26412645

26422646
// Don't add dynamic if accessor is inlinable or tranparent.

test/SILGen/dynamically_replaceable.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,18 @@ var x = 10
367367
defer {
368368
let y = x
369369
}
370+
371+
// IMPLICIT-LABEL: sil [dynamically_replacable] [ossa] @$s23dynamically_replaceable16testWithLocalFunyyF
372+
// IMPLICIT-LABEL: sil private [ossa] @$s23dynamically_replaceable16testWithLocalFunyyF05localF0L_yyF
373+
// IMPLICIT-LABEL: sil private [ossa] @$s23dynamically_replaceable16testWithLocalFunyyF05localF0L_yyF0geF0L_yyF
374+
// IMPLICIT-LABEL: sil private [ossa] @$s23dynamically_replaceable16testWithLocalFunyyFyycfU_
375+
public func testWithLocalFun() {
376+
func localFun() {
377+
func localLocalFun() { print("bar") }
378+
print("foo")
379+
localLocalFun()
380+
}
381+
localFun()
382+
let unamedClosure = { print("foo") }
383+
unamedClosure()
384+
}

0 commit comments

Comments
 (0)