Skip to content

Commit 09b66c8

Browse files
author
Nathan Hawes
authored
Merge pull request #16356 from nathawes/rdar39951671-migrator-adding-unnecessary-objc-annotations-4.2
[4.2][migrator] Only enable Swift 3 ObjC inference warnings when migrating from Swift 3
2 parents 46518b3 + 3e4e354 commit 09b66c8

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

lib/Migrator/Migrator.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,22 @@ Migrator::performAFixItMigration(version::Version SwiftLanguageVersion) {
132132
LLVMArgs.erase(aarch64_use_tbi);
133133
}
134134

135-
// SE-0160: When migrating, always use the Swift 3 @objc inference rules,
136-
// which drives warnings with the "@objc" Fix-Its.
137-
Invocation.getLangOptions().EnableSwift3ObjCInference = true;
138-
139-
// The default behavior of the migrator, referred to as "minimal" migration
140-
// in SE-0160, only adds @objc Fix-Its to those cases where the Objective-C
141-
// entry point is explicitly used somewhere in the source code. The user
142-
// may also select a workflow that adds @objc for every declaration that
143-
// would infer @objc under the Swift 3 rules but would no longer infer
144-
// @objc in Swift 4.
145-
Invocation.getLangOptions().WarnSwift3ObjCInference =
146-
getMigratorOptions().KeepObjcVisibility
147-
? Swift3ObjCInferenceWarnings::Complete
148-
: Swift3ObjCInferenceWarnings::Minimal;
135+
if (StartInvocation.getLangOptions().EffectiveLanguageVersion.isVersion3()) {
136+
// SE-0160: When migrating, always use the Swift 3 @objc inference rules,
137+
// which drives warnings with the "@objc" Fix-Its.
138+
Invocation.getLangOptions().EnableSwift3ObjCInference = true;
139+
140+
// The default behavior of the migrator, referred to as "minimal" migration
141+
// in SE-0160, only adds @objc Fix-Its to those cases where the Objective-C
142+
// entry point is explicitly used somewhere in the source code. The user
143+
// may also select a workflow that adds @objc for every declaration that
144+
// would infer @objc under the Swift 3 rules but would no longer infer
145+
// @objc in Swift 4.
146+
Invocation.getLangOptions().WarnSwift3ObjCInference =
147+
getMigratorOptions().KeepObjcVisibility
148+
? Swift3ObjCInferenceWarnings::Complete
149+
: Swift3ObjCInferenceWarnings::Minimal;
150+
}
149151

150152
const auto &OrigFrontendOpts = StartInvocation.getFrontendOptions();
151153

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: objc_interop
22
// RUN: %target-swift-frontend -typecheck -swift-version 3 -enable-swift3-objc-inference %s
3-
// RUN: %empty-directory(%t) && %target-swift-frontend -c -primary-file %S/Inputs/objc_inference.swift -emit-migrated-file-path %t/complete_objc_inference.swift.result -emit-remap-file-path %t/complete_objc_inference.swift.remap -migrate-keep-objc-visibility -o /dev/null
4-
// RUN: diff -u %S/complete_objc_inference.swift.expected %t/complete_objc_inference.swift.result
3+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -primary-file %S/Inputs/objc_inference.swift -swift-version 3 -emit-migrated-file-path %t/complete_objc_inference.swift.result -emit-remap-file-path %t/complete_objc_inference.swift.remap -migrate-keep-objc-visibility -o /dev/null
4+
// RUN: diff -u %S/complete_objc_inference.swift.expected %t/complete_objc_inference.swift.result
55
// RUN: %target-swift-frontend -typecheck -swift-version 4 -enable-swift3-objc-inference %t/complete_objc_inference.swift.result
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: objc_interop
22
// RUN: %target-swift-frontend -typecheck -swift-version 3 %s
3-
// RUN: %empty-directory(%t) && %target-swift-frontend -c -primary-file %S/Inputs/objc_inference.swift -emit-migrated-file-path %t/minimal_objc_inference.swift.result -emit-remap-file-path %t/minimal_objc_inference.swift.remap -o /dev/null
3+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -primary-file %S/Inputs/objc_inference.swift -swift-version 3 -emit-migrated-file-path %t/minimal_objc_inference.swift.result -emit-remap-file-path %t/minimal_objc_inference.swift.remap -o /dev/null
44
// RUN: diff -u %S/minimal_objc_inference.swift.expected %t/minimal_objc_inference.swift.result
55
// RUN: %target-swift-frontend -typecheck -swift-version 4 %t/minimal_objc_inference.swift.result
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %target-swift-frontend -typecheck -swift-version 4 %s
3+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -primary-file %s -swift-version 4 -emit-migrated-file-path %t/objc_inference_noop.swift.result -emit-remap-file-path %t/objc_inference_noop.swift.remap -migrate-keep-objc-visibility -o /dev/null
4+
// RUN: diff -u %s %t/objc_inference_noop.swift.result
5+
6+
import Foundation
7+
8+
@objc class Foo : NSObject {
9+
var foo: Int = 10
10+
}

0 commit comments

Comments
 (0)