Skip to content

Commit 9f8b966

Browse files
authored
Add a test that checks that ClangImporter chooses only exported modules (#34392)
1 parent 9e27835 commit 9f8b966

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import ForeignA
2+
@_exported import ForeignB
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import HelperModule
2+
3+
public func funcTakingForeignStruct(_ param: ForeignStruct) {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "textual-header.h"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "textual-header.h"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ForeignA {
2+
// Nest the header in a sub-module to make sure these are handled correctly.
3+
module Sub {
4+
header "foreign-a.h"
5+
}
6+
}
7+
8+
module ForeignB {
9+
// Nest the header in a sub-module to make sure these are handled correctly.
10+
module Sub {
11+
header "foreign-b.h"
12+
}
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typedef struct {} ForeignStruct;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Check that when qualifying Clang types with a module name, we choose a
2+
// visible module. Clang types need special treatment because multiple Clang
3+
// modules can contain the same type declarations from a textually included
4+
// header, but not all of these modules may be visible. If we choose a module
5+
// that isn't visible, we produce `.swiftinterface` files that don't compile.
6+
//
7+
// To test this, the test sets up the following structure:
8+
//
9+
// MainModule (Swift module)
10+
// import HelperModule (Swift module)
11+
// import ForeignA (Clang module)
12+
// #include "textual-header.h"
13+
// @_exported import ForeignB (Clang module)
14+
// #include "textual-header.h"
15+
//
16+
// `ForeignA` and `ForeignB` both include the same textual header, which
17+
// defines the struct `ForeignStruct`.
18+
//
19+
// Because `ForeignB` is re-exported by `HelperModule`, it is visible from
20+
// `MainModule`, but `ForeignA` is not. This means that when `ForeignStruct` is
21+
// used in `MainModule`, its qualified name should be printed as
22+
// `ForeignB.ForeignStruct`, not `ForeignA.ForeignStruct`.
23+
//
24+
// In addition to checking for the presence of the expected string in the
25+
// `.swiftinterface` file, we also verify that it compiles without error.
26+
//
27+
// This is a regression test for https://bugs.swift.org/browse/SR-13032.
28+
29+
// RUN: %empty-directory(%t)
30+
// RUN: mkdir %t/helper_module %t/main_module
31+
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/helper_module/HelperModule.swiftmodule %S/Inputs/HelperModule.swift -I %S/Inputs
32+
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/main_module/MainModule.swiftmodule -emit-module-interface-path %t/main_module/MainModule.swiftinterface -I %t/helper_module %S/Inputs/MainModule.swift -I %S/Inputs
33+
// RUN: %FileCheck --input-file=%t/main_module/MainModule.swiftinterface %s
34+
// RUN: %target-swift-frontend -typecheck -swift-version 5 %t/main_module/MainModule.swiftinterface -I %t/helper_module -I %S/Inputs
35+
36+
// CHECK: public func funcTakingForeignStruct(_ param: ForeignB.ForeignStruct)

0 commit comments

Comments
 (0)