Skip to content

Commit 2fa75bd

Browse files
committed
Frontend: Downgrade 'already enabled' to a warning for experimental features.
If an upcoming feature was enabled by passing it via `-enable-experimental-feature`, downgrade the `already enabled` diagnostic to a warning. Resolves rdar://139087679.
1 parent 0c364a7 commit 2fa75bd

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,13 +1015,16 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10151015
Opts.EnableExperimentalStringProcessing = true;
10161016
}
10171017

1018-
auto enableUpcomingFeature = [&Opts, &Diags](Feature feature) -> bool {
1018+
auto enableUpcomingFeature = [&Opts, &Diags](Feature feature,
1019+
bool downgradeDiag) -> bool {
10191020
// Check if this feature was introduced already in this language version.
10201021
if (auto firstVersion = getFeatureLanguageVersion(feature)) {
10211022
if (Opts.isSwiftVersionAtLeast(*firstVersion)) {
1022-
Diags.diagnose(SourceLoc(), diag::error_upcoming_feature_on_by_default,
1023-
getFeatureName(feature), *firstVersion);
1024-
return true;
1023+
Diags
1024+
.diagnose(SourceLoc(), diag::error_upcoming_feature_on_by_default,
1025+
getFeatureName(feature), *firstVersion)
1026+
.limitBehaviorIf(downgradeDiag, DiagnosticBehavior::Warning);
1027+
return !downgradeDiag;
10251028
}
10261029
}
10271030

@@ -1062,7 +1065,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10621065
// -enable-experimental-feature flag too since the feature may have
10631066
// graduated from being experimental.
10641067
if (auto feature = getUpcomingFeature(value)) {
1065-
if (enableUpcomingFeature(*feature))
1068+
if (enableUpcomingFeature(*feature, /*downgradeDiag=*/true))
10661069
HadError = true;
10671070
}
10681071

@@ -1087,7 +1090,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10871090
if (!feature)
10881091
continue;
10891092

1090-
if (enableUpcomingFeature(*feature))
1093+
if (enableUpcomingFeature(*feature, /*downgradeDiag=*/false))
10911094
HadError = true;
10921095
}
10931096

test/Frontend/upcoming_feature.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
// Make sure that hasFeature(ConciseMagicFile) evaluates true when provided
22
// explicitly.
3-
// RUN: %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile %s
3+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ConciseMagicFile
44

55
// Make sure that hasFeature(ConciseMagicFile) evaluates true in Swift 6.
6-
// RUN: %target-swift-frontend -typecheck -swift-version 6 %s
6+
// RUN: %target-typecheck-verify-swift -swift-version 6
77

88
// Make sure that hasFeature(ConciseMagicFile) is off prior to Swift 6
9-
// RUN: %target-typecheck-verify-swift %s
9+
// RUN: %target-typecheck-verify-swift -verify-additional-prefix swift5-
1010

1111
// It's fine to provide a feature that we don't know about
12-
// RUN: %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile -enable-upcoming-feature UnknownFeature %s
13-
// RUN: %target-swift-frontend -typecheck -enable-upcoming-feature UnknownFeature -enable-upcoming-feature ConciseMagicFile %s
12+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ConciseMagicFile -enable-upcoming-feature UnknownFeature
13+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature UnknownFeature -enable-upcoming-feature ConciseMagicFile
1414

1515
// For compatibility when a feature graduates, it's fine to refer to an
1616
// upcoming feature as an experimental feature.
17-
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature ConciseMagicFile %s
17+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ConciseMagicFile
1818

1919
// It's not fine to provide a feature that's in the specified language version.
20-
// RUN: not %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s
21-
// RUN: not %target-swift-frontend -typecheck -enable-experimental-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s
20+
// RUN: not %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s --check-prefix=CHECK-ERROR
21+
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s --check-prefix=CHECK-WARN
2222

23-
// CHECK: error: upcoming feature 'ConciseMagicFile' is already enabled as of Swift version 6
23+
// CHECK-ERROR: error: upcoming feature 'ConciseMagicFile' is already enabled as of Swift version 6
24+
// CHECK-WARN: warning: upcoming feature 'ConciseMagicFile' is already enabled as of Swift version 6
2425

2526
#if hasFeature(ConciseMagicFile)
2627
let x = 0
2728
#else
28-
let y = boom // expected-error{{'boom'}}
29+
let y = boom // expected-swift5-error{{'boom'}}
2930
#endif

0 commit comments

Comments
 (0)