Skip to content

Commit

Permalink
[Serialization] Test the output on a crash due to a broken XRef
Browse files Browse the repository at this point in the history
  • Loading branch information
xymus committed Mar 18, 2021
1 parent c5c850c commit 9f71f46
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/Serialization/Recovery/crash-xref.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// Test xref error description by removing a type from a module after building
/// a client.
// RUN: %empty-directory(%t)

/// Compile module A with a type and an empty module B.
// RUN: %target-swift-frontend %s -emit-module-path %t/A.swiftmodule -module-name A -D LIB
// RUN: %target-swift-frontend %s -emit-module-path %t/B.swiftmodule -module-name B
#if LIB
public struct SomeType {
public init() {}
}

/// Compile a client using the type from A.
// RUN: %target-swift-frontend %s -emit-module-path %t/Client.swiftmodule -module-name Client -D CLIENT -I %t
#elseif CLIENT
import A
import B

public func foo() -> A.SomeType { fatalError() }

/// Swap A and B around! A is now empty and B defines the type.
// RUN: %target-swift-frontend %s -emit-module-path %t/A.swiftmodule -module-name A
// RUN: %target-swift-frontend %s -emit-module-path %t/B.swiftmodule -module-name B -D LIB
#endif // Empty

/// Read from the client to get an xref error to the type missing from A.
// RUN: not --crash %target-swift-frontend -emit-sil %t/Client.swiftmodule -module-name Client -I %t -disable-deserialization-recovery 2> %t/stderr

// RUN: cat %t/stderr | %FileCheck %s
// CHECK: *** DESERIALIZATION FAILURE (please include this section in any bug report) ***
// CHECK-NEXT: Could not deserialize type for 'foo()'
// CHECK-NEXT: Caused by: top-level value not found
// CHECK-NEXT: Cross-reference to 'SomeType' in module 'A'
// CHECK-NEXT: Notes:
// CHECK-NEXT: * 'SomeType' was not found in module 'B', but there is one in module 'B'. If this is imported from clang, please make sure the header is part of a single clang module.

0 comments on commit 9f71f46

Please sign in to comment.