Skip to content

Commit 177b606

Browse files
authored
[Serialization] Fix message for using an older compiler's module file (#17340) (#17474)
Previously: "module compiled with Swift 4.1 cannot be imported in Swift 4.1.50" (i.e. following the -swift-version flag) Now: "module compiled with Swift 4.1 cannot be imported by the Swift 4.2 compiler" I'm pretty sure this is what I intended to do all along, and I just messed it up when I originally implemented it. This is especially important when working with downloadable toolchains, which would say "module compiled with Swift 4.2 cannot be imported in Swift 4.1.50", which is not really the problem at all. Now it'll fall back to the more generic "module file was created by an older version of the compiler" error. (cherry picked from commit 2c40c6b)
1 parent 5f4f14b commit 177b606

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ ERROR(serialization_module_too_new,Fatal,
575575
"module file was created by a newer version of the compiler: %0",
576576
(StringRef))
577577
ERROR(serialization_module_language_version_mismatch,Fatal,
578-
"module compiled with Swift %0 cannot be imported in Swift %1: %2",
578+
"module compiled with Swift %0 cannot be imported by the Swift %1 "
579+
"compiler: %2",
579580
(StringRef, StringRef, StringRef))
580581
ERROR(serialization_module_too_old,Fatal,
581582
"module file was created by an older version of the compiler; "

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <system_error>
2828

2929
using namespace swift;
30+
using swift::version::Version;
3031

3132
namespace {
3233
using AccessPathElem = std::pair<Identifier, SourceLoc>;
@@ -240,7 +241,7 @@ FileUnit *SerializedModuleLoader::loadAST(
240241

241242
SmallString<32> versionBuf;
242243
llvm::raw_svector_ostream versionString(versionBuf);
243-
versionString << Ctx.LangOpts.EffectiveLanguageVersion;
244+
versionString << Version::getCurrentLanguageVersion();
244245
if (versionString.str() == shortVersion)
245246
return false;
246247

test/Serialization/version-mismatches.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-old/ -show-diagnostics-after-fatal 2>&1 | %FileCheck -check-prefix CHECK -check-prefix TOO-OLD %s
22
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new/ -show-diagnostics-after-fatal 2>&1 | %FileCheck -check-prefix CHECK -check-prefix TOO-NEW %s
33

4-
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-old-language/ -show-diagnostics-after-fatal 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
5-
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
6-
74
// Update this line when "-swift-version 3" is no longer supported.
8-
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal -swift-version 3 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE-3 %s
9-
// Update this line when "-swift-version 4" is no longer supported.
10-
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal -swift-version 4 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE-4 %s
5+
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal -swift-version 3 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
6+
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal -swift-version 4 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
7+
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-new-language/ -show-diagnostics-after-fatal -swift-version 5 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
8+
9+
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs/too-old-language/ -show-diagnostics-after-fatal 2>&1 | %FileCheck -check-prefix CHECK -check-prefix LANGUAGE %s
1110

1211
import Library
1312
// TOO-OLD: :[[@LINE-1]]:8: error: module file was created by an older version of the compiler; rebuild 'Library' and try again: {{.*}}too-old/Library.swiftmodule{{$}}
1413
// TOO-NEW: :[[@LINE-2]]:8: error: module file was created by a newer version of the compiler: {{.*}}too-new/Library.swiftmodule{{$}}
1514

16-
// Update this line when the default language version changes
17-
// LANGUAGE: :[[@LINE-5]]:8: error: module compiled with Swift X.Y cannot be imported in Swift {{.+}}.{{.+}}: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}
18-
19-
// Update this line when "-swift-version 3" is no longer supported.
20-
// LANGUAGE-3: :[[@LINE-8]]:8: error: module compiled with Swift X.Y cannot be imported in Swift 3.{{.+}}: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}
21-
// Update this line when "-swift-version 3" is no longer supported.
22-
// LANGUAGE-4: :[[@LINE-10]]:8: error: module compiled with Swift X.Y cannot be imported in Swift 4.{{.+}}: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}
15+
// Update this line when the compiler version changes.
16+
// LANGUAGE: :[[@LINE-5]]:8: error: module compiled with Swift X.Y cannot be imported by the Swift 4.{{.+}} compiler: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}
2317

2418
// Compiler thinks that the module is empty in all cases.
2519
// CHECK: :[[@LINE+1]]:1: error: module 'Library' has no member named 'foo'

0 commit comments

Comments
 (0)