Skip to content

Commit b4901ea

Browse files
jrose-appletkremenek
authored andcommitted
[PrintAsObjC] Fix class properties with generic parameters. (#3092)
public static var myDictionary: [String: AnyObject] becomes SWIFT_CLASS_PROPERTY(@Property (nonatomic, class, readonly, copy) NSDictionary<NSString *, id> * _Nonnull myDictionary;) and the commas in the ObjC generic break the macro, just like they do with C++ templates. Fix this by making the macro variadic. rdar://problem/26879147 (cherry picked from commit a679aca)
1 parent 1466227 commit b4901ea

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,9 +1796,9 @@ class ModuleWriter {
17961796
"#endif\n"
17971797
"#if !defined(SWIFT_CLASS_PROPERTY)\n"
17981798
"# if __has_feature(objc_class_property)\n"
1799-
"# define SWIFT_CLASS_PROPERTY(X) X\n"
1799+
"# define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__\n"
18001800
"# else\n"
1801-
"# define SWIFT_CLASS_PROPERTY(X)\n"
1801+
"# define SWIFT_CLASS_PROPERTY(...)\n"
18021802
"# endif\n"
18031803
"#endif\n"
18041804
"\n"

test/PrintAsObjC/classes.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ public class NonObjCClass { }
409409
// CHECK-NEXT: + (void)setStaticString:(NSString * _Nonnull)value;
410410
// CHECK-NEXT: SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly) double staticDouble;)
411411
// CHECK-NEXT: + (double)staticDouble;
412+
// CHECK-NEXT: SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) NSDictionary<NSString *, NSString *> * _Nonnull staticDictionary;)
413+
// CHECK-NEXT: + (NSDictionary<NSString *, NSString *> * _Nonnull)staticDictionary;
412414
// CHECK-NEXT: @property (nonatomic, strong) Properties * _Nullable wobble;
413415
// CHECK-NEXT: @property (nonatomic, getter=isEnabled, setter=setIsEnabled:) BOOL enabled;
414416
// CHECK-NEXT: @property (nonatomic, getter=isAnimated) BOOL animated;
@@ -490,6 +492,7 @@ public class NonObjCClass { }
490492
static var staticDouble: Double {
491493
return 2.0
492494
}
495+
static var staticDictionary: [String: String] { return [:] }
493496

494497
@objc(wobble) var wibble: Properties?
495498

0 commit comments

Comments
 (0)