File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -645,6 +645,12 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
645
645
}
646
646
}
647
647
648
+ static bool isLazy (PatternBindingDecl *PBD) {
649
+ if (auto var = PBD->getSingleVar ())
650
+ return var->getAttrs ().hasAttribute <LazyAttr>();
651
+ return false ;
652
+ }
653
+
648
654
void TypeChecker::checkPatternBindingCaptures (NominalTypeDecl *typeDecl) {
649
655
auto &ctx = typeDecl->getASTContext ();
650
656
@@ -669,7 +675,7 @@ void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
669
675
/* ObjC=*/ false );
670
676
init->walk (finder);
671
677
672
- if (finder.getDynamicSelfCaptureLoc ().isValid ()) {
678
+ if (finder.getDynamicSelfCaptureLoc ().isValid () && ! isLazy (PBD) ) {
673
679
ctx.Diags .diagnose (finder.getDynamicSelfCaptureLoc (),
674
680
diag::dynamic_self_stored_property_init);
675
681
}
Original file line number Diff line number Diff line change @@ -253,4 +253,13 @@ class SelfStoredPropertyInit {
253
253
static func myValue( ) -> Int { return 123 }
254
254
255
255
var value = Self . myValue ( ) // expected-error {{covariant 'Self' type cannot be referenced from a stored property initializer}}
256
- }
256
+ }
257
+
258
+ // rdar://problem/55273931 - erroneously rejecting 'Self' in lazy initializer
259
+ class Foo {
260
+ static var value : Int = 17
261
+
262
+ lazy var doubledValue : Int = {
263
+ Self . value * 2
264
+ } ( )
265
+ }
You can’t perform that action at this time.
0 commit comments