Skip to content

Commit ed6baaa

Browse files
gregomnijckarter
authored andcommitted
Add transitive capture test
1 parent a924c92 commit ed6baaa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/SILGen/capture-transitive.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-emit-silgen -enable-sil-ownership %s | %FileCheck %s
2+
// SR-8398
3+
func fibonacci(_ n: Int) -> Int {
4+
var cache: [Int: Int] = [:]
5+
6+
func recursive(_ m: Int) -> Int {
7+
return cache[m] ?? {
8+
// Make sure cache is only captured once in the closure
9+
// CHECK: implicit closure #1 in recursive #1
10+
// CHECK-LABEL: sil private [transparent] @{{.*}}9fibonacci{{.*}}9recursive{{.*}} : $@convention(thin) (Int, @guaranteed { var Dictionary<Int, Int> }) -> (Int, @error Error)
11+
// CHECK: closure #1 in implicit closure #1 in recursive #1
12+
// CHECK-LABEL: sil private @{{.*}}9fibonacci{{.*}}9recursive{{.*}} : $@convention(thin) (Int, @guaranteed { var Dictionary<Int, Int> }) -> Int
13+
let output = m < 2 ? m : recursive(m - 1) + recursive(m - 2)
14+
cache[m] = output
15+
return output
16+
}()
17+
}
18+
return recursive(n)
19+
}
20+

0 commit comments

Comments
 (0)