Files
swift-mirror/test/ModuleInterface/language_mode.swift
Allan Shortlidge 1ca0d87e2b 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.

This is a re-attempt of https://github.com/swiftlang/swift/pull/84327.

Resolves rdar://145168219.
2026-02-25 12:42:02 -08:00

28 lines
1.2 KiB
Swift

// RUN: %empty-directory(%t)
// 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: 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 \
// RUN: -emit-module-interface-path %t.swiftinterface \
// RUN: -emit-module -o /dev/null -language-mode 5
// RUN: %FileCheck %s --check-prefix CHECK-SWIFTINTERFACE < %t.swiftinterface
// RUN: %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 -swift-version 5
// RUN: %FileCheck %s --check-prefix CHECK-SWIFTINTERFACE < %t.swiftinterface
// CHECK-SWIFTINTERFACE: swift-module-flags:
// CHECK-SWIFTINTERFACE-SAME: -enable-library-evolution
// CHECK-SWIFTINTERFACE-SAME: -module-name Test
// CHECK-SWIFTINTERFACE-SAME: {{-swift-version|-language-mode}} 5