Skip to content

Commit ae5acb9

Browse files
committed
[Type checker] Check for recursion when evaluating @objc on a property.
Fixes crash from rdar://problem/33093935.
1 parent 9565f0d commit ae5acb9

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ bool swift::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
759759
if (!VD->hasInterfaceType()) {
760760
VD->getASTContext().getLazyResolver()->resolveDeclSignature(
761761
const_cast<VarDecl *>(VD));
762+
if (!VD->hasInterfaceType()) {
763+
VD->diagnose(diag::recursive_type_reference, VD->getDescriptiveKind(),
764+
VD->getName());
765+
return false;
766+
}
762767
}
763768

764769
Type T = VD->getDeclContext()->mapTypeIntoContext(VD->getInterfaceType());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -primary-file %s %S/Inputs/0177-rdar-33093935-other.swift -verify
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
extension A {
8+
static func superclass() -> AnyObject? { return nil }
9+
@objc var name: String { return "hi" }
10+
}
11+
12+
class B: A {
13+
@objc var foo = superclass()?.name // expected-error{{property 'foo' references itself}}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Foundation
2+
3+
class A: NSObject { }

0 commit comments

Comments
 (0)