Skip to content

Commit d56a927

Browse files
committed
[ClangImporter] Handle property with getter that returns instancetype
We just import this as a property, and Swift doesn't support properties with dynamic Self type, even if they are read-only. Don't mark the getter as returning dynamic Self in this case. (This was only a problem in builds with the AST verifier turned on.) https://bugs.swift.org/browse/SR-5684
1 parent 267d63e commit d56a927

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ namespace {
37723772

37733773
// If the method has a related result type that is representable
37743774
// in Swift as DynamicSelf, do so.
3775-
if (decl->hasRelatedResultType()) {
3775+
if (!prop && decl->hasRelatedResultType()) {
37763776
result->setDynamicSelf(true);
37773777
resultTy = DynamicSelfType::get(dc->getSelfInterfaceType(),
37783778
Impl.SwiftContext);

test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,8 @@ typedef SomeCell <NSCopying> *CopyableSomeCell;
198198
// Note the custom setter name here; this is important.
199199
@property (setter=takeFooForBar:) BOOL fooForBar;
200200
@end
201+
202+
@interface InstancetypeAccessor : NSObject
203+
@property (class, readonly) InstancetypeAccessor *prop;
204+
+ (instancetype)prop;
205+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -I %S/Inputs/custom-modules %s -verify > /dev/null
2+
3+
// REQUIRES: objc_interop
4+
// expected-no-diagnostics
5+
6+
// This file tests the AST verifier, which performs extra checks when there are
7+
// no errors emitted. Please do not add any.
8+
9+
10+
import ObjCParseExtras
11+
12+
func test() {
13+
// Properties with instancetype getters.
14+
_ = InstancetypeAccessor.prop
15+
}

0 commit comments

Comments
 (0)