mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ClangImporter] Don't import compatibility methods named 'print'. (#10928)
...because they make things harder for people trying to use
Swift.print. Before:
error: 'print' has been renamed to 'printDocument(_:)'
After:
error: use of 'print' nearly matches global function
'print(_:separator:terminator:)' in module 'Swift'
rather than instance method 'print(_:extra:)'
(This actually occurs with AppKit's NSDocument, so it's not just a
hypothetical concern.)
rdar://problem/32839733
This commit is contained in:
@@ -2,6 +2,31 @@ Name: APINotesFrameworkTest
|
||||
Classes:
|
||||
- Name: A
|
||||
SwiftObjCMembers: true
|
||||
- Name: PrintingInterference
|
||||
Methods:
|
||||
- Selector: 'print:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'printDocument(_:)'
|
||||
- Name: PrintingRenamed
|
||||
Methods:
|
||||
- Selector: 'print'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'printDocument()'
|
||||
- Selector: 'print:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'printDocument(_:)'
|
||||
- Selector: 'print:options:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'printDocument(_:options:)'
|
||||
- Selector: 'print'
|
||||
MethodKind: Class
|
||||
SwiftName: 'printDocument()'
|
||||
- Selector: 'print:'
|
||||
MethodKind: Class
|
||||
SwiftName: 'printDocument(_:)'
|
||||
- Selector: 'print:options:'
|
||||
MethodKind: Class
|
||||
SwiftName: 'printDocument(_:options:)'
|
||||
- Name: TestProperties
|
||||
Properties:
|
||||
- Name: accessorsOnly
|
||||
@@ -43,6 +68,31 @@ Tags:
|
||||
SwiftVersions:
|
||||
- Version: 3.0
|
||||
Classes:
|
||||
- Name: PrintingInterference
|
||||
Methods:
|
||||
- Selector: 'print:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'print(_:)'
|
||||
- Name: PrintingRenamed
|
||||
Methods:
|
||||
- Selector: 'print'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'print()'
|
||||
- Selector: 'print:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'print(_:)'
|
||||
- Selector: 'print:options:'
|
||||
MethodKind: Instance
|
||||
SwiftName: 'print(_:options:)'
|
||||
- Selector: 'print'
|
||||
MethodKind: Class
|
||||
SwiftName: 'print()'
|
||||
- Selector: 'print:'
|
||||
MethodKind: Class
|
||||
SwiftName: 'print(_:)'
|
||||
- Selector: 'print:options:'
|
||||
MethodKind: Class
|
||||
SwiftName: 'print(_:options:)'
|
||||
- Name: TestProperties
|
||||
Methods:
|
||||
- Selector: accessorsOnlyRenamedRetyped
|
||||
|
||||
@@ -17,5 +17,20 @@
|
||||
@property (nullable) id importantInstanceProperty __attribute__((swift_name("finalInstanceProperty")));
|
||||
@end
|
||||
|
||||
@interface PrintingRenamed : Base
|
||||
- (void)print;
|
||||
- (void)print:(id)thing;
|
||||
- (void)print:(id)thing options:(id)options;
|
||||
|
||||
+ (void)print;
|
||||
+ (void)print:(id)thing;
|
||||
+ (void)print:(id)thing options:(id)options;
|
||||
@end
|
||||
|
||||
@interface PrintingInterference : Base
|
||||
- (void)print:(id)thing; // Only this one gets renamed.
|
||||
- (void)print:(id)thing extra:(id)options;
|
||||
@end
|
||||
|
||||
#pragma clang assume_nonnull end
|
||||
#endif // __OBJC__
|
||||
|
||||
@@ -140,4 +140,46 @@ func testRenamedProtocolMembers(obj: ProtoWithManyRenames) {
|
||||
// CHECK-DIAGS-4-NOT: :[[@LINE-1]]:{{[0-9]+}}:
|
||||
}
|
||||
|
||||
extension PrintingRenamed {
|
||||
func testDroppingRenamedPrints() {
|
||||
// CHECK-DIAGS-3: [[@LINE+1]]:{{[0-9]+}}: warning: use of 'print' treated as a reference to instance method
|
||||
print()
|
||||
// CHECK-DIAGS-4-NOT: [[@LINE-1]]:{{[0-9]+}}:
|
||||
|
||||
// CHECK-DIAGS-3: [[@LINE+1]]:{{[0-9]+}}: warning: use of 'print' treated as a reference to instance method
|
||||
print(self)
|
||||
// CHECK-DIAGS-4-NOT: [[@LINE-1]]:{{[0-9]+}}:
|
||||
|
||||
// CHECK-DIAGS-3-NOT: [[@LINE+1]]:{{[0-9]+}}:
|
||||
print(self, options: self)
|
||||
// CHECK-DIAGS-4: [[@LINE-1]]:{{[0-9]+}}: error: argument labels '(_:, options:)' do not match any available overloads
|
||||
}
|
||||
|
||||
static func testDroppingRenamedPrints() {
|
||||
// CHECK-DIAGS-3: [[@LINE+1]]:{{[0-9]+}}: warning: use of 'print' treated as a reference to class method
|
||||
print()
|
||||
// CHECK-DIAGS-4-NOT: [[@LINE-1]]:{{[0-9]+}}:
|
||||
|
||||
// CHECK-DIAGS-3: [[@LINE+1]]:{{[0-9]+}}: warning: use of 'print' treated as a reference to class method
|
||||
print(self)
|
||||
// CHECK-DIAGS-4-NOT: [[@LINE-1]]:{{[0-9]+}}:
|
||||
|
||||
// CHECK-DIAGS-3-NOT: [[@LINE+1]]:{{[0-9]+}}:
|
||||
print(self, options: self)
|
||||
// CHECK-DIAGS-4: [[@LINE-1]]:{{[0-9]+}}: error: argument labels '(_:, options:)' do not match any available overloads
|
||||
}
|
||||
}
|
||||
|
||||
extension PrintingInterference {
|
||||
func testDroppingRenamedPrints() {
|
||||
// CHECK-DIAGS-3: [[@LINE+1]]:{{[0-9]+}}: warning: use of 'print' treated as a reference to instance method
|
||||
print(self)
|
||||
// CHECK-DIAGS-4: [[@LINE-1]]:{{[0-9]+}}: error: use of 'print' nearly matches global function 'print(_:separator:terminator:)' in module 'Swift' rather than instance method 'print(_:extra:)'
|
||||
|
||||
// CHECK-DIAGS-3-NOT: [[@LINE+1]]:{{[0-9]+}}:
|
||||
print(self, extra: self)
|
||||
// CHECK-DIAGS-4-NOT: [[@LINE-1]]:{{[0-9]+}}:
|
||||
}
|
||||
}
|
||||
|
||||
let unrelatedDiagnostic: Int = nil
|
||||
|
||||
Reference in New Issue
Block a user