File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -769,6 +769,12 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
769
769
maybeDiagnoseCaptures (expr, AFR);
770
770
}
771
771
772
+ static bool isLazy (PatternBindingDecl *PBD) {
773
+ if (auto var = PBD->getSingleVar ())
774
+ return var->getAttrs ().hasAttribute <LazyAttr>();
775
+ return false ;
776
+ }
777
+
772
778
void TypeChecker::checkPatternBindingCaptures (NominalTypeDecl *typeDecl) {
773
779
for (auto member : typeDecl->getMembers ()) {
774
780
// Ignore everything other than PBDs.
@@ -791,7 +797,7 @@ void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
791
797
/* ObjC=*/ false );
792
798
init->walk (finder);
793
799
794
- if (finder.getDynamicSelfCaptureLoc ().isValid ()) {
800
+ if (finder.getDynamicSelfCaptureLoc ().isValid () && ! isLazy (PBD) ) {
795
801
diagnose (finder.getDynamicSelfCaptureLoc (),
796
802
diag::dynamic_self_stored_property_init);
797
803
}
Original file line number Diff line number Diff line change @@ -183,3 +183,12 @@ class SelfStoredPropertyInit {
183
183
184
184
var value = Self . myValue ( ) // expected-error {{covariant 'Self' type cannot be referenced from a stored property initializer}}
185
185
}
186
+
187
+ // rdar://problem/55273931 - erroneously rejecting 'Self' in lazy initializer
188
+ class Foo {
189
+ static var value : Int = 17
190
+
191
+ lazy var doubledValue : Int = {
192
+ Self . value * 2
193
+ } ( )
194
+ }
You can’t perform that action at this time.
0 commit comments