Skip to content

Commit a9c4695

Browse files
committed
[PrintAsObjC] Silence -Wnullability for the generated declarations. (#10247)
Since Swift 3 and Swift 4 might have different views of an Objective-C API's nullability, we can end up with incompatible overrides, including with inherited initializers. This is unfortunate but also realistic; the Swift 3 code is /not/ set up to handle the new nullability used by Swift 4 and Objective-C. Just silence the warning. (It would be nice to not print inherited initializers at all, but that would mean making sure there are no convenience initializers we have to print as well. Otherwise the class would get mistaken for one without explicit designated initializers.) rdar://problem/32571301
1 parent 46952ad commit a9c4695

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,7 @@ class ModuleWriter {
27132713
"# pragma clang diagnostic ignored \"-Wpragma-clang-attribute\"\n"
27142714
"#endif\n"
27152715
"#pragma clang diagnostic ignored \"-Wunknown-pragmas\"\n"
2716+
"#pragma clang diagnostic ignored \"-Wnullability\"\n"
27162717
"\n"
27172718
"SWIFT_MODULE_NAMESPACE_PUSH(\"" << M.getNameStr() << "\")\n"
27182719
<< os.str()

test/PrintAsObjC/Inputs/custom-modules/NestedClass.apinotes

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Name: VersionedFMWK
2+
SwiftVersions:
3+
- Version: 3.0
4+
Classes:
5+
- Name: InnerClass
6+
SwiftName: InnerClass
7+
- Name: NullabilityBase
8+
Methods:
9+
- Selector: 'initFormerlyFailableValue:'
10+
MethodKind: Instance
11+
NullabilityOfRet: O
12+
- Selector: 'processNowNullableArgument:'
13+
MethodKind: Instance
14+
Parameters:
15+
- Position: 0
16+
Nullability: N
17+
Tags:
18+
- Name: InnerStruct
19+
SwiftName: InnerStruct
20+
Typedefs:
21+
- Name: InnerAlias
22+
SwiftName: InnerAlias
23+
- Name: InnerAnonStruct
24+
SwiftName: InnerAnonStruct

test/PrintAsObjC/Inputs/custom-modules/NestedClass.h renamed to test/PrintAsObjC/Inputs/custom-modules/VersionedFMWK.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ typedef struct {
1919

2020
typedef int InnerAlias __attribute__((swift_name("Outer.InnerA")));
2121

22+
23+
@interface NullabilityBase : NSObject
24+
- (nonnull instancetype)initFormerlyFailableValue:(NSInteger)value __attribute__((objc_designated_initializer));
25+
- (void)processNowNullableArgument:(nullable NSObject *)object;
26+
@end

test/PrintAsObjC/Inputs/custom-modules/module.map

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module CompatibilityAlias {
3838
export *
3939
}
4040

41-
module NestedClass {
42-
header "NestedClass.h"
41+
module VersionedFMWK {
42+
header "VersionedFMWK.h"
4343
export *
4444
}

test/PrintAsObjC/versioned.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/../Inputs/clang-importer-sdk -I %t) -parse-as-library %t/versioned.swiftmodule -typecheck -I %S/Inputs/custom-modules -emit-objc-header-path %t/versioned.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module -swift-version 3
1515
// RUN: %FileCheck %s < %t/versioned.h
1616
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ %t/versioned.h
17-
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ -fno-modules -Qunused-arguments %t/versioned.h -include Foundation.h -include NestedClass.h
17+
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ -fno-modules -Qunused-arguments %t/versioned.h -include Foundation.h -include VersionedFMWK.h
1818

19-
import NestedClass
19+
import VersionedFMWK
20+
21+
// CHECK-LABEL: @interface NullabilitySub
22+
@objc class NullabilitySub: NullabilityBase {
23+
// CHECK-NEXT: - (void)processNowNullableArgument:(NSObject * _Nonnull)object;
24+
override func processNowNullableArgument(_ object: NSObject) {}
25+
// CHECK-NEXT: - (nullable instancetype)initFormerlyFailableValue:(NSInteger)value OBJC_DESIGNATED_INITIALIZER;
26+
} // CHECK-NEXT: @end
2027

2128
// CHECK-LABEL: @interface UsesNestedClass
2229
@objc class UsesNestedClass : NSObject {

0 commit comments

Comments
 (0)