Skip to content

Commit c4ed40d

Browse files
committed
[Type checker] Fix crash with invalid overriding property.
When an overriding property containing willSet or didSet is not within a type, the type checker could crash due to a missing "self" declaration. Check this condition. Fixes rdar://problem/57040259.
1 parent f5665df commit c4ed40d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,8 @@ StorageImplInfoRequest::evaluate(Evaluator &evaluator,
27702770

27712771
// Check if we have observers.
27722772
} else if (hasWillSet || hasDidSet) {
2773-
if (storage->getAttrs().hasAttribute<OverrideAttr>()) {
2773+
if (storage->getAttrs().hasAttribute<OverrideAttr>() &&
2774+
storage->getDeclContext()->isTypeContext()) {
27742775
readImpl = ReadImplKind::Inherited;
27752776
} else {
27762777
readImpl = ReadImplKind::Stored;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
class A { }
3+
class B: A {
4+
func foo(_: () -> ()) {
5+
6+
override var prop: Any? {
7+
didSet { }
8+
}
9+
}

0 commit comments

Comments
 (0)