mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[TypeChecker] Avoid checking lazy property accessors if they haven't been synthesized yet
Ttheir availability is going to match the property itself. This is a workaround for lazy type-checking because synthesis of accessors for such properties requires a reference to `self` which won't be available because pattern binding for the variable was skipped. Resolves: rdar://129359362 Resolves: rdar://159463230 Resolves: https://github.com/swiftlang/swift/issues/84041
This commit is contained in:
@@ -2707,6 +2707,25 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
// Avoid checking lazy property accessors if they haven't been
|
||||
// synthesized yet, their availability is going to match the
|
||||
// property itself. This is a workaround for lazy type-checking
|
||||
// because synthesis of accessors for such properties requires
|
||||
// a reference to `self` which won't be available because pattern
|
||||
// binding for the variable was skipped.
|
||||
//
|
||||
// TODO: To fix this properly `getParentPatternBinding()`
|
||||
// has to be refactored into a request to help establish association
|
||||
// between a variable declaration and its pattern binding on demand
|
||||
// instead of by using `typeCheckPatternBinding` called from the
|
||||
// declaration checker.
|
||||
if (D->getAttrs().hasAttribute<LazyAttr>()) {
|
||||
auto *DC = D->getDeclContext();
|
||||
if (DC->isTypeContext() && !(D->getAccessor(AccessorKind::Get) &&
|
||||
D->getAccessor(AccessorKind::Set)))
|
||||
return;
|
||||
}
|
||||
|
||||
DeclAvailabilityFlags flags;
|
||||
if (InInOutExpr)
|
||||
flags |= DeclAvailabilityFlag::ForInout;
|
||||
|
||||
@@ -402,3 +402,7 @@ extension PublicStruct {
|
||||
lhs = rhs
|
||||
}
|
||||
}
|
||||
|
||||
public class LazyPropertyWithClosureType {
|
||||
public lazy var lazyVar: Int = { 2 }()
|
||||
}
|
||||
|
||||
@@ -142,3 +142,8 @@ func testOperators() {
|
||||
var a: PublicStruct
|
||||
a <<< PublicStruct(x: 2)
|
||||
}
|
||||
|
||||
func testLazyPropertyWithInitClosureReference(t: LazyPropertyWithClosureType) {
|
||||
_ = t.lazyVar
|
||||
t.lazyVar = 42
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user