File tree Expand file tree Collapse file tree 8 files changed +44
-16
lines changed Expand file tree Collapse file tree 8 files changed +44
-16
lines changed Original file line number Diff line number Diff line change @@ -767,6 +767,17 @@ namespace swift {
767
767
return limitBehaviorUntilSwiftVersion (limit, languageMode);
768
768
}
769
769
770
+ // / Limit the diagnostic behavior to warning until the next future
771
+ // / language mode.
772
+ // /
773
+ // / This should be preferred over passing the next major version to
774
+ // / `warnUntilSwiftVersion` to make it easier to find and update clients
775
+ // / when a new language mode is introduced.
776
+ // /
777
+ // / This helps stage in fixes for stricter diagnostics as warnings
778
+ // / until the next major language version.
779
+ InFlightDiagnostic &warnUntilFutureSwiftVersion ();
780
+
770
781
// / Limit the diagnostic behavior to warning until the specified version.
771
782
// /
772
783
// / This helps stage in fixes for stricter diagnostics as warnings
Original file line number Diff line number Diff line change @@ -131,6 +131,13 @@ class Version {
131
131
// / SWIFT_VERSION_MINOR.
132
132
static Version getCurrentLanguageVersion ();
133
133
134
+ // / Returns a major version to represent the next future language mode. This
135
+ // / exists to make it easier to find and update clients when a new language
136
+ // / mode is added.
137
+ static constexpr unsigned getFutureMajorLanguageVersion () {
138
+ return 7 ;
139
+ }
140
+
134
141
// List of backward-compatibility versions that we permit passing as
135
142
// -swift-version <vers>
136
143
static std::array<StringRef, 4 > getValidEffectiveVersions () {
Original file line number Diff line number Diff line change @@ -452,7 +452,7 @@ InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
452
452
// version. We do this before limiting the behavior, because
453
453
// wrapIn will result in the behavior of the wrapping diagnostic.
454
454
if (limit >= DiagnosticBehavior::Warning) {
455
- if (majorVersion > 6 ) {
455
+ if (majorVersion >= version::Version::getFutureMajorLanguageVersion () ) {
456
456
wrapIn (diag::error_in_a_future_swift_lang_mode);
457
457
} else {
458
458
wrapIn (diag::error_in_swift_lang_mode, majorVersion);
@@ -472,6 +472,11 @@ InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
472
472
return *this ;
473
473
}
474
474
475
+ InFlightDiagnostic &InFlightDiagnostic::warnUntilFutureSwiftVersion () {
476
+ using namespace version ;
477
+ return warnUntilSwiftVersion (Version::getFutureMajorLanguageVersion ());
478
+ }
479
+
475
480
InFlightDiagnostic &
476
481
InFlightDiagnostic::warnUntilSwiftVersion (unsigned majorVersion) {
477
482
return limitBehaviorUntilSwiftVersion (DiagnosticBehavior::Warning,
Original file line number Diff line number Diff line change @@ -181,16 +181,19 @@ std::optional<Version> Version::getEffectiveLanguageVersion() const {
181
181
static_assert (SWIFT_VERSION_MAJOR == 6 ,
182
182
" getCurrentLanguageVersion is no longer correct here" );
183
183
return Version::getCurrentLanguageVersion ();
184
- case 7 :
185
- // Allow version '7' in asserts compilers *only* so that we can start
186
- // testing changes planned for after Swift 6. Note that it's still not
187
- // listed in `Version::getValidEffectiveVersions()`.
188
- // FIXME: When Swift 7 becomes real, remove 'REQUIRES: swift7' from tests
189
- // using '-swift-version 7'.
184
+
185
+ // FIXME: When Swift 7 becomes real, remove 'REQUIRES: swift7' from tests
186
+ // using '-swift-version 7'.
187
+
188
+ case Version::getFutureMajorLanguageVersion ():
189
+ // Allow the future language mode version in asserts compilers *only* so
190
+ // that we can start testing changes planned for after the current latest
191
+ // language mode. Note that it'll not be listed in
192
+ // `Version::getValidEffectiveVersions()`.
190
193
#ifdef NDEBUG
191
194
LLVM_FALLTHROUGH;
192
195
#else
193
- return Version{7 };
196
+ return Version{Version::getFutureMajorLanguageVersion () };
194
197
#endif
195
198
default :
196
199
return std::nullopt;
Original file line number Diff line number Diff line change @@ -2243,11 +2243,12 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
2243
2243
invalidImplicitSelfShouldOnlyWarn510 (base, closure)) {
2244
2244
warnUntilVersion.emplace (6 );
2245
2245
}
2246
- // Prior to Swift 7, downgrade to a warning if we're in a macro to preserve
2247
- // compatibility with the Swift 6 diagnostic behavior where we previously
2248
- // skipped diagnosing.
2249
- if (!Ctx.isSwiftVersionAtLeast (7 ) && isInMacro ())
2250
- warnUntilVersion.emplace (7 );
2246
+ // Prior to the next language mode, downgrade to a warning if we're in a
2247
+ // macro to preserve compatibility with the Swift 6 diagnostic behavior
2248
+ // where we previously skipped diagnosing.
2249
+ auto futureVersion = version::Version::getFutureMajorLanguageVersion ();
2250
+ if (!Ctx.isSwiftVersionAtLeast (futureVersion) && isInMacro ())
2251
+ warnUntilVersion.emplace (futureVersion);
2251
2252
2252
2253
auto diag = Ctx.Diags .diagnose (loc, ID, std::move (Args)...);
2253
2254
if (warnUntilVersion)
Original file line number Diff line number Diff line change @@ -1249,7 +1249,7 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
1249
1249
diagnose (attr->getLocation (),
1250
1250
diag::access_control_non_objc_open_member, VD)
1251
1251
.fixItReplace (attr->getRange (), " public" )
1252
- .warnUntilSwiftVersion ( 7 );
1252
+ .warnUntilFutureSwiftVersion ( );
1253
1253
}
1254
1254
}
1255
1255
}
Original file line number Diff line number Diff line change @@ -2676,7 +2676,7 @@ namespace {
2676
2676
fromType, toType);
2677
2677
2678
2678
if (downgradeToWarning)
2679
- diag.warnUntilSwiftVersion ( 7 );
2679
+ diag.warnUntilFutureSwiftVersion ( );
2680
2680
}
2681
2681
2682
2682
for (auto type : nonSendableTypes) {
Original file line number Diff line number Diff line change @@ -5169,7 +5169,8 @@ static bool diagnoseTypeWitnessAvailability(
5169
5169
return false ;
5170
5170
5171
5171
// In Swift 6 and earlier type witness availability diagnostics are warnings.
5172
- const unsigned warnBeforeVersion = 7 ;
5172
+ using namespace version ;
5173
+ const unsigned warnBeforeVersion = Version::getFutureMajorLanguageVersion ();
5173
5174
bool shouldError =
5174
5175
ctx.LangOpts .EffectiveLanguageVersion .isVersionAtLeast (warnBeforeVersion);
5175
5176
You can’t perform that action at this time.
0 commit comments