Skip to content

Commit 9067051

Browse files
committed
Frontend: Require explicit language mode when emitting swiftinterfaces.
If a .swiftinterface file does not include an explicit `-language-mode` option (or its predecessor `-swift-version`) and needs to be built as a dependency of a client compilation, then the invocation to build the module from interface would end up inheriting the language mode that the client code is built with. This can result in spurious type checking diagnostics or even mis-compilation. To ensure that a module interface is always built using the language mode that its source code was originally built with, require an explicit `-language-mode` option when emitting swiftinterface files. In #84307 this diagnostic was downgraded to a warning. The failures it caused in PR testing should now be resolved. Resolves rdar://145168219.
1 parent 2b6ea81 commit 9067051

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10351035
if (!isValid)
10361036
diagnoseSwiftVersion(vers, A, Args, Diags);
10371037
} else if (FrontendOpts.InputsAndOutputs.hasModuleInterfaceOutputPath()) {
1038-
Diags.diagnose({}, diag::error_module_interface_requires_language_mode)
1039-
.limitBehavior(DiagnosticBehavior::Warning);
1040-
// FIXME: Make this an error again (rdar://145168219)
1041-
// HadError = true;
1038+
Diags.diagnose({}, diag::error_module_interface_requires_language_mode);
1039+
HadError = true;
10421040
}
10431041

10441042
if (auto A = Args.getLastArg(OPT_package_description_version)) {

test/ModuleInterface/language_mode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
3+
// RUN: not %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
44
// RUN: -enable-library-evolution -module-name Test \
55
// RUN: -emit-module-interface-path %t.swiftinterface \
66
// RUN: -emit-module -o /dev/null 2>&1 | %FileCheck %s
77

8-
// CHECK: <unknown>:0: warning: emitting module interface files requires '-language-mode'
8+
// CHECK: <unknown>:0: error: emitting module interface files requires '-language-mode'
99

1010
// RUN: %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
1111
// RUN: -enable-library-evolution -module-name Test \

0 commit comments

Comments
 (0)