Skip to content

Commit a971a0c

Browse files
committed
AST: Add convenience for limiting diags to warnings in swiftinterfaces.
Sometimes it's useful to be more lenient when type checking swiftinterfaces since restrictions that could be dropped in the future will manifest in resilient libraries being incompatible with older compilers otherwise.
1 parent 3f0885d commit a971a0c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,15 @@ namespace swift {
564564
/// until the next major language version.
565565
InFlightDiagnostic &warnUntilSwiftVersion(unsigned majorVersion);
566566

567+
/// Limit the diagnostic behavior to warning if the context is a
568+
/// swiftinterface.
569+
///
570+
/// This is useful for diagnostics for restrictions that may be lifted by a
571+
/// future version of the compiler. In such cases, it may be helpful to
572+
/// avoid failing to build a module from its interface if the interface was
573+
/// emitted using a compiler that no longer has the restriction.
574+
InFlightDiagnostic &warnInSwiftInterface(const DeclContext *context);
575+
567576
/// Conditionally limit the diagnostic behavior to warning until
568577
/// the specified version. If the condition is false, no limit is
569578
/// imposed, meaning (presumably) it is treated as an error.

lib/AST/DiagnosticEngine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
334334
return *this;
335335
}
336336

337+
InFlightDiagnostic &
338+
InFlightDiagnostic::warnInSwiftInterface(const DeclContext *context) {
339+
auto sourceFile = context->getParentSourceFile();
340+
if (sourceFile && sourceFile->Kind == SourceFileKind::Interface) {
341+
return limitBehavior(DiagnosticBehavior::Warning);
342+
}
343+
344+
return *this;
345+
}
346+
337347
InFlightDiagnostic &
338348
InFlightDiagnostic::wrapIn(const Diagnostic &wrapper) {
339349
// Save current active diagnostic into WrappedDiagnostics, ignoring state

0 commit comments

Comments
 (0)