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 @@ -2608,6 +2608,25 @@ class ExprAvailabilityWalker : public BaseDiagnosticWalker {
26082608 return ;
26092609 }
26102610
2611+ // Avoid checking lazy property accessors if they haven't been
2612+ // synthesized yet, their availability is going to match the
2613+ // property itself. This is a workaround for lazy type-checking
2614+ // because synthesis of accessors for such properties requires
2615+ // a reference to `self` which won't be available because pattern
2616+ // binding for the variable was skipped.
2617+ //
2618+ // TODO: To fix this properly `getParentPatternBinding()`
2619+ // has to be refactored into a request to help establish association
2620+ // between a variable declaration and its pattern binding on demand
2621+ // instead of by using `typeCheckPatternBinding` called from the
2622+ // declaration checker.
2623+ if (D->getAttrs ().hasAttribute <LazyAttr>()) {
2624+ auto *DC = D->getDeclContext ();
2625+ if (DC->isTypeContext () && !(D->getAccessor (AccessorKind::Get) &&
2626+ D->getAccessor (AccessorKind::Set)))
2627+ return ;
2628+ }
2629+
26112630 // Check availability of accessor functions.
26122631 // TODO: if we're talking about an inlineable storage declaration,
26132632 // this probably needs to be refined to not assume that the accesses are
Original file line number Diff line number Diff line change @@ -378,3 +378,7 @@ extension PublicStruct {
378378 lhs = rhs
379379 }
380380}
381+
382+ public class LazyPropertyWithClosureType {
383+ public lazy var lazyVar : Int = { 2 } ( )
384+ }
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