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 {
390390 return limitBehaviorUntilSwiftVersion (limit, languageMode);
391391 }
392392
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+
393404 // / Limit the diagnostic behavior to warning until the specified version.
394405 // /
395406 // / 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 {
131131 // / SWIFT_VERSION_MINOR.
132132 static Version getCurrentLanguageVersion ();
133133
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+
134141 // List of backward-compatibility versions that we permit passing as
135142 // -swift-version <vers>
136143 static std::array<StringRef, 4 > getValidEffectiveVersions () {
Original file line number Diff line number Diff line change @@ -452,7 +452,7 @@ InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
452452 // version. We do this before limiting the behavior, because
453453 // wrapIn will result in the behavior of the wrapping diagnostic.
454454 if (limit >= DiagnosticBehavior::Warning) {
455- if (majorVersion > 6 ) {
455+ if (majorVersion >= version::Version::getFutureMajorLanguageVersion () ) {
456456 wrapIn (diag::error_in_a_future_swift_lang_mode);
457457 } else {
458458 wrapIn (diag::error_in_swift_lang_mode, majorVersion);
@@ -472,6 +472,11 @@ InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
472472 return *this ;
473473}
474474
475+ InFlightDiagnostic &InFlightDiagnostic::warnUntilFutureSwiftVersion () {
476+ using namespace version ;
477+ return warnUntilSwiftVersion (Version::getFutureMajorLanguageVersion ());
478+ }
479+
475480InFlightDiagnostic &
476481InFlightDiagnostic::warnUntilSwiftVersion (unsigned majorVersion) {
477482 return limitBehaviorUntilSwiftVersion (DiagnosticBehavior::Warning,
Original file line number Diff line number Diff line change @@ -181,16 +181,19 @@ std::optional<Version> Version::getEffectiveLanguageVersion() const {
181181 static_assert (SWIFT_VERSION_MAJOR == 6 ,
182182 " getCurrentLanguageVersion is no longer correct here" );
183183 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()`.
190193#ifdef NDEBUG
191194 LLVM_FALLTHROUGH;
192195#else
193- return Version{7 };
196+ return Version{Version::getFutureMajorLanguageVersion () };
194197#endif
195198 default :
196199 return std::nullopt ;
Original file line number Diff line number Diff line change @@ -2240,11 +2240,12 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
22402240 invalidImplicitSelfShouldOnlyWarn510 (base, closure)) {
22412241 warnUntilVersion.emplace (6 );
22422242 }
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);
22482249
22492250 auto diag = Ctx.Diags .diagnose (loc, ID, std::move (Args)...);
22502251 if (warnUntilVersion)
Original file line number Diff line number Diff line change @@ -1260,7 +1260,7 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
12601260 diagnose (attr->getLocation (),
12611261 diag::access_control_non_objc_open_member, VD)
12621262 .fixItReplace (attr->getRange (), " public" )
1263- .warnUntilSwiftVersion ( 7 );
1263+ .warnUntilFutureSwiftVersion ( );
12641264 }
12651265 }
12661266 }
Original file line number Diff line number Diff line change @@ -2675,7 +2675,7 @@ namespace {
26752675 fromType, toType);
26762676
26772677 if (downgradeToWarning)
2678- diag.warnUntilSwiftVersion ( 7 );
2678+ diag.warnUntilFutureSwiftVersion ( );
26792679 }
26802680
26812681 for (auto type : nonSendableTypes) {
Original file line number Diff line number Diff line change @@ -5185,7 +5185,8 @@ static bool diagnoseTypeWitnessAvailability(
51855185 return false ;
51865186
51875187 // 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 ();
51895190 bool shouldError =
51905191 ctx.LangOpts .EffectiveLanguageVersion .isVersionAtLeast (warnBeforeVersion);
51915192
You can’t perform that action at this time.
0 commit comments