Skip to content

Commit 50945ef

Browse files
committed
[Diagnostics] Add InFlightDiagnostic::limitBehaviorUntilSwiftVersion to
downgrade or suppress errors until a specified language version.
1 parent 09432a9 commit 50945ef

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ namespace swift {
575575
return limitBehavior(limit);
576576
}
577577

578+
/// Limit the diagnostic behavior to \c limit until the specified
579+
/// version.
580+
///
581+
/// This helps stage in fixes for stricter diagnostics as warnings
582+
/// until the next major language version.
583+
InFlightDiagnostic &limitBehaviorUntilSwiftVersion(
584+
DiagnosticBehavior limit, unsigned majorVersion);
585+
578586
/// Limit the diagnostic behavior to warning until the specified version.
579587
///
580588
/// This helps stage in fixes for stricter diagnostics as warnings

lib/AST/DiagnosticEngine.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,10 @@ InFlightDiagnostic::limitBehavior(DiagnosticBehavior limit) {
328328
}
329329

330330
InFlightDiagnostic &
331-
InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
331+
InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
332+
DiagnosticBehavior limit, unsigned majorVersion) {
332333
if (!Engine->languageVersion.isVersionAtLeast(majorVersion)) {
333-
limitBehavior(DiagnosticBehavior::Warning)
334+
limitBehavior(limit)
334335
.wrapIn(diag::error_in_future_swift_version, majorVersion);
335336
}
336337

@@ -343,6 +344,12 @@ InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
343344
return *this;
344345
}
345346

347+
InFlightDiagnostic &
348+
InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
349+
return limitBehaviorUntilSwiftVersion(DiagnosticBehavior::Warning,
350+
majorVersion);
351+
}
352+
346353
InFlightDiagnostic &
347354
InFlightDiagnostic::warnInSwiftInterface(const DeclContext *context) {
348355
auto sourceFile = context->getParentSourceFile();

0 commit comments

Comments
 (0)