Skip to content

[3.1] [Clang importer] When importing a property as accessors, use accessor types #6906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3457,10 +3457,21 @@ namespace {
Optional<ForeignErrorConvention> errorConvention;
bodyParams.push_back(nullptr);
Type type;

// If we have a property accessor, find the corresponding property
// declaration.
const clang::ObjCPropertyDecl *prop = nullptr;
if (decl->isPropertyAccessor()) {
const clang::ObjCPropertyDecl *prop = decl->findPropertyDecl();
if (!prop)
return nullptr;
prop = decl->findPropertyDecl();
if (!prop) return nullptr;

// If we're importing just the accessors (not the property), ignore
// the property.
if (shouldImportPropertyAsAccessors(prop))
prop = nullptr;
}

if (prop) {
// If the matching property is in a superclass, or if the getter and
// setter are redeclared in a potentially incompatible way, bail out.
if (prop->getGetterMethodDecl() != decl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ SwiftVersions:
- Version: 3.0
Classes:
- Name: TestProperties
Methods:
- Selector: accessorsOnlyRenamedRetyped
MethodKind: Instance
SwiftName: 'renamedAndRetyped()'
ResultType: 'id _Nonnull'
- Selector: 'setAccessorsOnlyRenamedRetyped:'
MethodKind: Instance
SwiftName: 'setRenamedAndRetyped(_:)'
Parameters:
- Position: 0
Type: 'id _Nullable'
- Selector: accessorsOnlyRenamedRetypedClass
MethodKind: Class
SwiftName: 'renamedAndRetypedClass()'
ResultType: 'id _Nonnull'
- Selector: 'setAccessorsOnlyRenamedRetypedClass:'
MethodKind: Class
SwiftName: 'setRenamedAndRetypedClass(_:)'
Parameters:
- Position: 0
Type: 'id _Nullable'
Properties:
- Name: accessorsOnlyInVersion3
PropertyKind: Instance
Expand All @@ -52,6 +73,12 @@ SwiftVersions:
- Name: accessorsOnlyForClassExceptInVersion3
PropertyKind: Class
SwiftImportAsAccessors: false
- Name: accessorsOnlyRenamedRetyped
PropertyKind: Instance
SwiftImportAsAccessors: true
- Name: accessorsOnlyRenamedRetypedClass
PropertyKind: Class
SwiftImportAsAccessors: true
Functions:
- Name: acceptDoublePointer
SwiftName: 'acceptPointer(_:)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ __attribute__((objc_root_class))
@property (nonatomic, readwrite, retain) id accessorsOnlyWithNewType;
@end

@interface TestProperties (AccessorsOnlyCustomized)
@property (nonatomic, readwrite, retain, null_resettable) id accessorsOnlyRenamedRetyped;
@property (class, nonatomic, readwrite, retain, null_resettable) id accessorsOnlyRenamedRetypedClass;
@end

#pragma clang assume_nonnull end
10 changes: 10 additions & 0 deletions test/APINotes/properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@
// CHECK-BOTH-DAG: func setAccessorsOnlyWithNewType(_ accessorsOnlyWithNewType: Base)

// CHECK-BOTH: {{^}$}}

// CHECK-SWIFT-3-DAG: func renamedAndRetyped() -> Any{{$}}
// CHECK-SWIFT-3-DAG: func setRenamedAndRetyped(_ accessorsOnlyRenamedRetyped: Any?)
// CHECK-SWIFT-4-DAG: var accessorsOnlyRenamedRetyped: Any!

// CHECK-SWIFT-3-DAG: class func renamedAndRetypedClass() -> Any{{$}}
// CHECK-SWIFT-3-DAG: class func setRenamedAndRetypedClass(_ accessorsOnlyRenamedRetypedClass: Any?)
// CHECK-SWIFT-4-DAG: class var accessorsOnlyRenamedRetypedClass: Any!

// CHECK-BOTH: {{^}$}}