Skip to content

Commit 4f9f0e8

Browse files
author
ematejska
authored
Merge pull request #6906 from DougGregor/import-property-accesors-3_1
[3.1] [Clang importer] When importing a property as accessors, use accessor types
2 parents bb4d406 + f64608b commit 4f9f0e8

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,10 +3457,21 @@ namespace {
34573457
Optional<ForeignErrorConvention> errorConvention;
34583458
bodyParams.push_back(nullptr);
34593459
Type type;
3460+
3461+
// If we have a property accessor, find the corresponding property
3462+
// declaration.
3463+
const clang::ObjCPropertyDecl *prop = nullptr;
34603464
if (decl->isPropertyAccessor()) {
3461-
const clang::ObjCPropertyDecl *prop = decl->findPropertyDecl();
3462-
if (!prop)
3463-
return nullptr;
3465+
prop = decl->findPropertyDecl();
3466+
if (!prop) return nullptr;
3467+
3468+
// If we're importing just the accessors (not the property), ignore
3469+
// the property.
3470+
if (shouldImportPropertyAsAccessors(prop))
3471+
prop = nullptr;
3472+
}
3473+
3474+
if (prop) {
34643475
// If the matching property is in a superclass, or if the getter and
34653476
// setter are redeclared in a potentially incompatible way, bail out.
34663477
if (prop->getGetterMethodDecl() != decl &&

test/APINotes/Inputs/custom-frameworks/APINotesFrameworkTest.framework/Headers/APINotesFrameworkTest.apinotes

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ SwiftVersions:
3939
- Version: 3.0
4040
Classes:
4141
- Name: TestProperties
42+
Methods:
43+
- Selector: accessorsOnlyRenamedRetyped
44+
MethodKind: Instance
45+
SwiftName: 'renamedAndRetyped()'
46+
ResultType: 'id _Nonnull'
47+
- Selector: 'setAccessorsOnlyRenamedRetyped:'
48+
MethodKind: Instance
49+
SwiftName: 'setRenamedAndRetyped(_:)'
50+
Parameters:
51+
- Position: 0
52+
Type: 'id _Nullable'
53+
- Selector: accessorsOnlyRenamedRetypedClass
54+
MethodKind: Class
55+
SwiftName: 'renamedAndRetypedClass()'
56+
ResultType: 'id _Nonnull'
57+
- Selector: 'setAccessorsOnlyRenamedRetypedClass:'
58+
MethodKind: Class
59+
SwiftName: 'setRenamedAndRetypedClass(_:)'
60+
Parameters:
61+
- Position: 0
62+
Type: 'id _Nullable'
4263
Properties:
4364
- Name: accessorsOnlyInVersion3
4465
PropertyKind: Instance
@@ -52,6 +73,12 @@ SwiftVersions:
5273
- Name: accessorsOnlyForClassExceptInVersion3
5374
PropertyKind: Class
5475
SwiftImportAsAccessors: false
76+
- Name: accessorsOnlyRenamedRetyped
77+
PropertyKind: Instance
78+
SwiftImportAsAccessors: true
79+
- Name: accessorsOnlyRenamedRetypedClass
80+
PropertyKind: Class
81+
SwiftImportAsAccessors: true
5582
Functions:
5683
- Name: acceptDoublePointer
5784
SwiftName: 'acceptPointer(_:)'

test/APINotes/Inputs/custom-frameworks/APINotesFrameworkTest.framework/Headers/Properties.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ __attribute__((objc_root_class))
2727
@property (nonatomic, readwrite, retain) id accessorsOnlyWithNewType;
2828
@end
2929

30+
@interface TestProperties (AccessorsOnlyCustomized)
31+
@property (nonatomic, readwrite, retain, null_resettable) id accessorsOnlyRenamedRetyped;
32+
@property (class, nonatomic, readwrite, retain, null_resettable) id accessorsOnlyRenamedRetypedClass;
33+
@end
34+
3035
#pragma clang assume_nonnull end

test/APINotes/properties.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@
4545
// CHECK-BOTH-DAG: func setAccessorsOnlyWithNewType(_ accessorsOnlyWithNewType: Base)
4646

4747
// CHECK-BOTH: {{^}$}}
48+
49+
// CHECK-SWIFT-3-DAG: func renamedAndRetyped() -> Any{{$}}
50+
// CHECK-SWIFT-3-DAG: func setRenamedAndRetyped(_ accessorsOnlyRenamedRetyped: Any?)
51+
// CHECK-SWIFT-4-DAG: var accessorsOnlyRenamedRetyped: Any!
52+
53+
// CHECK-SWIFT-3-DAG: class func renamedAndRetypedClass() -> Any{{$}}
54+
// CHECK-SWIFT-3-DAG: class func setRenamedAndRetypedClass(_ accessorsOnlyRenamedRetypedClass: Any?)
55+
// CHECK-SWIFT-4-DAG: class var accessorsOnlyRenamedRetypedClass: Any!
56+
57+
// CHECK-BOTH: {{^}$}}

0 commit comments

Comments
 (0)