Skip to content

Commit bd4e5e7

Browse files
committed
Sema: Add test guarding against accidental SPI reexport via clang modules
Exported imports are common between clang modules. Make sure we test against accidently reexporting Swift SPIs through these exported imports.
1 parent d976ea6 commit bd4e5e7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/SPI/accidental-reexport.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// Guard that we don't reexport the SPIs accidentally through the common
2+
/// reexported imports between clang modules.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
7+
// RUN: %target-swift-frontend -emit-module %t/Overlayed.swift -I %t -o %t
8+
// RUN: %target-swift-frontend -typecheck -verify %t/Client.swift -I %t
9+
// RUN: %target-swift-frontend -typecheck -verify %t/LowerClient.swift -I %t
10+
11+
//--- module.modulemap
12+
module Overlayed {
13+
header "Overlayed.h"
14+
}
15+
16+
module Middle {
17+
header "Middle.h"
18+
export *
19+
}
20+
21+
module LowerMiddle {
22+
header "LowerMiddle.h"
23+
export *
24+
}
25+
26+
//--- Overlayed.h
27+
//--- Overlayed.swift
28+
@_exported import Overlayed
29+
30+
public func funcPublic() {}
31+
32+
@_spi(X)
33+
public func funcSPI() {}
34+
35+
//--- Middle.h
36+
#include <Overlayed.h>
37+
38+
//--- LowerMiddle.h
39+
#include <Middle.h>
40+
41+
//--- Client.swift
42+
@_spi(X) import Middle
43+
44+
funcPublic()
45+
funcSPI() // expected-error {{cannot find 'funcSPI' in scope}}
46+
47+
//--- LowerClient.swift
48+
@_spi(X) import LowerMiddle
49+
50+
funcPublic()
51+
funcSPI() // expected-error {{cannot find 'funcSPI' in scope}}

0 commit comments

Comments
 (0)