File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -2707,6 +2707,25 @@ class ExprAvailabilityWalker : public BaseDiagnosticWalker {
27072707 return ;
27082708 }
27092709
2710+ // Avoid checking lazy property accessors if they haven't been
2711+ // synthesized yet, their availability is going to match the
2712+ // property itself. This is a workaround for lazy type-checking
2713+ // because synthesis of accessors for such properties requires
2714+ // a reference to `self` which won't be available because pattern
2715+ // binding for the variable was skipped.
2716+ //
2717+ // TODO: To fix this properly `getParentPatternBinding()`
2718+ // has to be refactored into a request to help establish association
2719+ // between a variable declaration and its pattern binding on demand
2720+ // instead of by using `typeCheckPatternBinding` called from the
2721+ // declaration checker.
2722+ if (D->getAttrs ().hasAttribute <LazyAttr>()) {
2723+ auto *DC = D->getDeclContext ();
2724+ if (DC->isTypeContext () && !(D->getAccessor (AccessorKind::Get) &&
2725+ D->getAccessor (AccessorKind::Set)))
2726+ return ;
2727+ }
2728+
27102729 DeclAvailabilityFlags flags;
27112730 if (InInOutExpr)
27122731 flags |= DeclAvailabilityFlag::ForInout;
Original file line number Diff line number Diff line change @@ -402,3 +402,7 @@ extension PublicStruct {
402402 lhs = rhs
403403 }
404404}
405+
406+ public class LazyPropertyWithClosureType {
407+ public lazy var lazyVar : Int = { 2 } ( )
408+ }
Original file line number Diff line number Diff line change @@ -142,3 +142,8 @@ func testOperators() {
142142 var a : PublicStruct
143143 a <<< PublicStruct ( x: 2 )
144144}
145+
146+ func testLazyPropertyWithInitClosureReference( t: LazyPropertyWithClosureType ) {
147+ _ = t. lazyVar
148+ t. lazyVar = 42
149+ }
You can’t perform that action at this time.
0 commit comments