Skip to content

Commit 33ed767

Browse files
authored
[ClangImporter] Preserve the names of imported ObjC properties. (#6182)
This is necessary for proper working of #keyPath, as well as improving the experience of PrintAsObjC. rdar://problem/28543037
1 parent 1f21213 commit 33ed767

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4265,7 +4265,7 @@ namespace {
42654265
// Turn this into a computed property.
42664266
// FIXME: Fake locations for '{' and '}'?
42674267
result->makeComputed(SourceLoc(), getter, setter, nullptr, SourceLoc());
4268-
addObjCAttribute(result, None);
4268+
addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier()));
42694269
applyPropertyOwnership(result, decl->getPropertyAttributesAsWritten());
42704270

42714271
// Handle attributes.

test/PrintAsObjC/Inputs/custom-modules/override.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- (NSUInteger)foo:(NSUInteger)x y:(NSUInteger)y;
77

88
@property(readonly,getter=getProp) NSUInteger prop;
9+
@property(readonly) NSInteger originalName __attribute__((swift_name("renamedProp")));
910

1011
- (id)objectAtIndexedSubscript:(NSUInteger)idx;
1112

test/PrintAsObjC/override.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import OverrideBase
2323
class A_Child : Base {
2424
// CHECK-NEXT: @property (nonatomic, readonly, getter=getProp) NSUInteger prop;
2525
override var prop: Int { return 0 }
26+
// CHECK-NEXT: @property (nonatomic, readonly) NSInteger originalName;
27+
override var renamedProp: Int { return 0 }
2628
// CHECK-NEXT: - (id _Nullable)objectAtIndexedSubscript:(NSUInteger)x SWIFT_WARN_UNUSED_RESULT;
2729
override subscript(x: Int) -> Any? { return nil }
2830

test/SILGen/Inputs/usr/include/Gizmo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef long NSInteger;
6565
+ (Gizmo*)nonNilGizmo __attribute__((swift_name("nonNilGizmo()")));
6666
@property Gizmo* nonNilGizmoProperty;
6767
@property (unsafe_unretained) Gizmo* unownedNonNilGizmoProperty;
68+
69+
@property id originalName __attribute__((swift_name("renamedProp")));
6870
@end
6971

7072
@interface Guisemeau : Gizmo

test/SILGen/objc_keypath.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import ObjectiveC
66
import Foundation
7+
import gizmo
78

89
@objc class Foo : NSObject {
910
@objc(firstProp) var fooProp: Foo?
@@ -14,4 +15,10 @@ import Foundation
1415
func createKeyPath() -> String {
1516
// CHECK: string_literal utf8 "firstProp.secondProp"
1617
return #keyPath(Foo.fooProp.stringProp)
17-
}
18+
} // CHECK: } // end sil function '_TF12objc_keypath13createKeyPathFT_SS'
19+
20+
// CHECK-LABEL: sil hidden @_TF12objc_keypath21createKeyPathImportedFT_SS
21+
func createKeyPathImported() -> String {
22+
// CHECK: string_literal utf8 "originalName"
23+
return #keyPath(Gizmo.renamedProp)
24+
} // CHECK: } // end sil function '_TF12objc_keypath21createKeyPathImportedFT_SS'

0 commit comments

Comments
 (0)