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 @@ -390,6 +390,17 @@ namespace swift {
390
390
return limitBehaviorUntilSwiftVersion (limit, languageMode);
391
391
}
392
392
393
+ // / Limit the diagnostic behavior to warning until the next future
394
+ // / language mode.
395
+ // /
396
+ // / This should be preferred over passing the next major version to
397
+ // / `warnUntilSwiftVersion` to make it easier to find and update clients
398
+ // / when a new language mode is introduced.
399
+ // /
400
+ // / This helps stage in fixes for stricter diagnostics as warnings
401
+ // / until the next major language version.
402
+ InFlightDiagnostic &warnUntilFutureSwiftVersion ();
403
+
393
404
// / Limit the diagnostic behavior to warning until the specified version.
394
405
// /
395
406
// / 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 @@ -2240,11 +2240,12 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
2240
2240
invalidImplicitSelfShouldOnlyWarn510 (base, closure)) {
2241
2241
warnUntilVersion.emplace (6 );
2242
2242
}
2243
- // Prior to Swift 7, downgrade to a warning if we're in a macro to preserve
2244
- // compatibility with the Swift 6 diagnostic behavior where we previously
2245
- // skipped diagnosing.
2246
- if (!Ctx.isSwiftVersionAtLeast (7 ) && isInMacro ())
2247
- warnUntilVersion.emplace (7 );
2243
+ // Prior to the next language mode, downgrade to a warning if we're in a
2244
+ // macro to preserve compatibility with the Swift 6 diagnostic behavior
2245
+ // where we previously skipped diagnosing.
2246
+ auto futureVersion = version::Version::getFutureMajorLanguageVersion ();
2247
+ if (!Ctx.isSwiftVersionAtLeast (futureVersion) && isInMacro ())
2248
+ warnUntilVersion.emplace (futureVersion);
2248
2249
2249
2250
auto diag = Ctx.Diags .diagnose (loc, ID, std::move (Args)...);
2250
2251
if (warnUntilVersion)
Original file line number Diff line number Diff line change @@ -1260,7 +1260,7 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
1260
1260
diagnose (attr->getLocation (),
1261
1261
diag::access_control_non_objc_open_member, VD)
1262
1262
.fixItReplace (attr->getRange (), " public" )
1263
- .warnUntilSwiftVersion ( 7 );
1263
+ .warnUntilFutureSwiftVersion ( );
1264
1264
}
1265
1265
}
1266
1266
}
Original file line number Diff line number Diff line change @@ -2675,7 +2675,7 @@ namespace {
2675
2675
fromType, toType);
2676
2676
2677
2677
if (downgradeToWarning)
2678
- diag.warnUntilSwiftVersion ( 7 );
2678
+ diag.warnUntilFutureSwiftVersion ( );
2679
2679
}
2680
2680
2681
2681
for (auto type : nonSendableTypes) {
Original file line number Diff line number Diff line change @@ -5185,7 +5185,8 @@ static bool diagnoseTypeWitnessAvailability(
5185
5185
return false ;
5186
5186
5187
5187
// In Swift 6 and earlier type witness availability diagnostics are warnings.
5188
- const unsigned warnBeforeVersion = 7 ;
5188
+ using namespace version ;
5189
+ const unsigned warnBeforeVersion = Version::getFutureMajorLanguageVersion ();
5189
5190
bool shouldError =
5190
5191
ctx.LangOpts .EffectiveLanguageVersion .isVersionAtLeast (warnBeforeVersion);
5191
5192
You can’t perform that action at this time.
0 commit comments