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 https://github.com/swiftlang/swift/pull/84307 this diagnostic was downgraded
to a warning. The failures it caused in PR testing should now be resolved.

Resolves rdar://145168219.
This commit is contained in:
Allan Shortlidge
2025-09-16 10:22:17 -07:00
parent 2b6ea81b9e
commit 9067051c29
2 changed files with 4 additions and 6 deletions

View File

@@ -1,11 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
// RUN: not %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
// RUN: -enable-library-evolution -module-name Test \
// RUN: -emit-module-interface-path %t.swiftinterface \
// RUN: -emit-module -o /dev/null 2>&1 | %FileCheck %s
// CHECK: <unknown>:0: warning: emitting module interface files requires '-language-mode'
// CHECK: <unknown>:0: error: emitting module interface files requires '-language-mode'
// RUN: %swift_frontend_plain -target %target-swift-5.1-abi-triple %s \
// RUN: -enable-library-evolution -module-name Test \