Skip to content

Commit 41f824d

Browse files
committed
[test] Add a lazy local test case
This hit an assertion I was trying to add to make sure we don't try to recursively type-check when type-checking a closure. Currently we can end up type-checking the initializer for `x` while generating constraints for the closure due to the fact that we eagerly compute the interface type for the backing lazy storage var. We ought to make that computation lazy, but in the mean time, add this test case.
1 parent ec8afd5 commit 41f824d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

test/SILGen/lazy_locals.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ func lazyLocalWithNestedClosure() {
4343
return 3
4444
}()
4545
}
46+
47+
func lazyLocalInClosure() {
48+
// Make sure we can type-check.
49+
_ = {
50+
lazy var x = 0
51+
return x
52+
}
53+
}

test/expr/closure/closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,3 +1792,15 @@ class rdar129475277 {
17921792
}
17931793
}
17941794
}
1795+
1796+
class TestLazyLocal {
1797+
func bar() -> Int { 0 }
1798+
func foo() {
1799+
_ = { // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
1800+
lazy var x = bar()
1801+
// expected-error@-1 {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}}
1802+
// expected-note@-2 {{reference 'self.' explicitly}}
1803+
return x
1804+
}
1805+
}
1806+
}

0 commit comments

Comments
 (0)