Skip to content

Commit 290dc04

Browse files
committed
[Features] Gate SE-0383 behind an upcoming feature flag.
(cherry picked from commit 7cb9880)
1 parent 2bd67d9 commit 290dc04

16 files changed

+62
-42
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros", tru
115115
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
116116
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
117117
UPCOMING_FEATURE(BareSlashRegexLiterals, 354, 6)
118+
UPCOMING_FEATURE(DeprecateApplicationMain, 383, 6)
118119
UPCOMING_FEATURE(ImportObjcForwardDeclarations, 384, 6)
119120
UPCOMING_FEATURE(DisableOutwardActorInference, 401, 6)
120121

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,6 +3220,10 @@ static bool usesFeatureStrictConcurrency(Decl *decl) {
32203220
return false;
32213221
}
32223222

3223+
static bool usesFeatureDeprecateApplicationMain(Decl *decl) {
3224+
return false;
3225+
}
3226+
32233227
static bool usesFeatureImportObjcForwardDeclarations(Decl *decl) {
32243228
ClangNode clangNode = decl->getClangNode();
32253229
if (!clangNode)

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,15 +2346,16 @@ void AttributeChecker::checkApplicationMainAttribute(DeclAttribute *attr,
23462346
attr->setInvalid();
23472347
}
23482348

2349-
diagnose(attr->getLocation(),
2350-
diag::attr_ApplicationMain_deprecated,
2351-
applicationMainKind)
2352-
.warnUntilSwiftVersion(6);
2353-
2354-
diagnose(attr->getLocation(),
2355-
diag::attr_ApplicationMain_deprecated_use_attr_main)
2356-
.fixItReplace(attr->getRange(), "@main");
2349+
if (C.LangOpts.hasFeature(Feature::DeprecateApplicationMain)) {
2350+
diagnose(attr->getLocation(),
2351+
diag::attr_ApplicationMain_deprecated,
2352+
applicationMainKind)
2353+
.warnUntilSwiftVersion(6);
23572354

2355+
diagnose(attr->getLocation(),
2356+
diag::attr_ApplicationMain_deprecated_use_attr_main)
2357+
.fixItReplace(attr->getRange(), "@main");
2358+
}
23582359

23592360
if (attr->isInvalid())
23602361
return;

test/TBD/objc-entry-point.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir -o /dev/null -validate-tbd-against-ir=all -parse-as-library -verify -enable-testing %s
22
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir -o /dev/null -validate-tbd-against-ir=all -parse-as-library -verify %s
33

4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir -o /dev/null -validate-tbd-against-ir=all -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- -enable-testing %s
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-upcoming-feature DeprecateApplicationMain -emit-ir -o /dev/null -validate-tbd-against-ir=all -parse-as-library -verify -verify-additional-prefix deprecated- %s
6+
47
// REQUIRES: objc_interop
58
import AppKit
69

@@ -9,7 +12,7 @@ import AppKit
912
// present in the TBD.
1013
let globalConstantWithLazyInitializer: String = "hello, world"
1114

12-
@NSApplicationMain // expected-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
13-
// expected-note@-1 {{use @main instead}} {{1-19=@main}}
15+
@NSApplicationMain // expected-deprecated-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
16+
// expected-deprecated-note@-1 {{use @main instead}} {{1-19=@main}}
1417
class MyDelegate: NSObject, NSApplicationDelegate {
1518
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import AppKit
67

7-
@NSApplicationMain // expected-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
8-
// expected-note@-1 {{use @main instead}} {{1-19=@main}}
8+
@NSApplicationMain // expected-deprecated-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
9+
// expected-deprecated-note@-1 {{use @main instead}} {{1-19=@main}}
910
class MyDelegate: NSObject, NSApplicationDelegate {
1011
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import AppKit
67

78
class DelegateBase : NSObject, NSApplicationDelegate { }
89

9-
@NSApplicationMain // expected-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
10-
// expected-note@-1 {{use @main instead}} {{1-19=@main}}
10+
@NSApplicationMain // expected-deprecated-warning {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
11+
// expected-deprecated-note@-1 {{use @main instead}} {{1-19=@main}}
1112
class MyDelegate : DelegateBase { }
1213

test/attr/ApplicationMain/attr_NSApplicationMain_multi_file/another_delegate.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -module-name main -emit-module-path %t.swiftmodule -primary-file %s %S/delegate.swift
55
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -module-name main -parse-as-library -typecheck %t.swiftmodule -primary-file %S/delegate.swift -verify -verify-ignore-unknown
66

7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -module-name main -parse-as-library -typecheck -enable-upcoming-feature DeprecateApplicationMain %t.swiftmodule -primary-file %S/delegate.swift -verify -verify-ignore-unknown -verify-additional-prefix deprecated-
8+
79
// REQUIRES: objc_interop
810

911
import AppKit
1012

1113
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute can only apply to one class in a module}}
12-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
13-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
14+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
15+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1416
class EvilDelegate: NSObject, NSApplicationDelegate {
1517
}
1618

test/attr/ApplicationMain/attr_NSApplicationMain_multi_file/delegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import AppKit
99

1010
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute can only apply to one class in a module}}
11-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
12-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
11+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
12+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1313
class MyDelegate: NSObject, NSApplicationDelegate {
1414
}
1515

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
3+
24

35
// REQUIRES: objc_interop
46

57
import AppKit
68

79
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute can only apply to one class in a module}}
8-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
9-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
10+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
11+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1012
class MyDelegate1: NSObject, NSApplicationDelegate {
1113
}
1214

1315
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute can only apply to one class in a module}}
14-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
15-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
16+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
17+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1618
class MyDelegate2: NSObject, NSApplicationDelegate {
1719
}
1820

1921
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute can only apply to one class in a module}}
20-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
21-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
22+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
23+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
2224
class MyDelegate3: NSObject, NSApplicationDelegate {
2325
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import AppKit
67

78
@NSApplicationMain // expected-error{{'NSApplicationMain' class must conform to the 'NSApplicationDelegate' protocol}}
8-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
9-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
9+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
10+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1011
class MyNonDelegate {
1112
}

test/attr/ApplicationMain/attr_NSApplicationMain_with_main/delegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import AppKit
99

1010
@NSApplicationMain // expected-error{{'NSApplicationMain' attribute cannot be used in a module that contains top-level code}}
11-
// expected-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
12-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
11+
// expected-deprecated-warning@-1 {{'NSApplicationMain' is deprecated; this is an error in Swift 6}}
12+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1313
class MyDelegate: NSObject, NSApplicationDelegate {
1414
}
1515

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import UIKit
67

7-
@UIApplicationMain // expected-warning {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
8-
// expected-note@-1 {{use @main instead}} {{1-19=@main}}
8+
@UIApplicationMain // expected-deprecated-warning {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
9+
// expected-deprecated-note@-1 {{use @main instead}} {{1-19=@main}}
910
class MyDelegate: NSObject, UIApplicationDelegate {
1011
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import UIKit
67

78
class DelegateBase : NSObject, UIApplicationDelegate { }
89

9-
@UIApplicationMain // expected-warning {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
10-
// expected-note@-1 {{use @main instead}} {{1-19=@main}}
10+
@UIApplicationMain // expected-deprecated-warning {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
11+
// expected-deprecated-note@-1 {{use @main instead}} {{1-19=@main}}
1112
class MyDelegate : DelegateBase { }
1213

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import UIKit
67

78
@UIApplicationMain // expected-error{{'UIApplicationMain' attribute can only apply to one class in a module}}
8-
// expected-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
9-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
9+
// expected-deprecated-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
10+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1011
class MyDelegate1: NSObject, UIApplicationDelegate {
1112
}
1213

1314
@UIApplicationMain // expected-error{{'UIApplicationMain' attribute can only apply to one class in a module}}
14-
// expected-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
15-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
15+
// expected-deprecated-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
16+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1617
class MyDelegate2: NSObject, UIApplicationDelegate {
1718
}
1819

1920
@UIApplicationMain // expected-error{{'UIApplicationMain' attribute can only apply to one class in a module}}
20-
// expected-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
21-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
21+
// expected-deprecated-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
22+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
2223
class MyDelegate3: NSObject, UIApplicationDelegate {
2324
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -enable-upcoming-feature DeprecateApplicationMain -verify -verify-additional-prefix deprecated- %s
23

34
// REQUIRES: objc_interop
45

56
import UIKit
67

78
@UIApplicationMain // expected-error{{'UIApplicationMain' class must conform to the 'UIApplicationDelegate' protocol}}
8-
// expected-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
9-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
9+
// expected-deprecated-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
10+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1011
class MyNonDelegate {
1112
}

test/attr/ApplicationMain/attr_UIApplicationMain_with_main/delegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import UIKit
99

1010
@UIApplicationMain // expected-error{{'UIApplicationMain' attribute cannot be used in a module that contains top-level code}}
11-
// expected-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
12-
// expected-note@-2 {{use @main instead}} {{1-19=@main}}
11+
// expected-deprecated-warning@-1 {{'UIApplicationMain' is deprecated; this is an error in Swift 6}}
12+
// expected-deprecated-note@-2 {{use @main instead}} {{1-19=@main}}
1313
class MyDelegate: NSObject, UIApplicationDelegate {
1414
}
1515

0 commit comments

Comments
 (0)