Skip to content

Commit 422e4cd

Browse files
committed
Sema: test @_spiOnly with warnings about superfluously public imports
The logic reporting superfluously public imports treats @_spiOnly imports as any public import. As such @_spiOnly shouldn't interfere with the diagnosics. Let's make sure we test the current behavior. In the future, we may want to extend the existing logic to report bare `public imports` that could be `@_spiOnly public import` if referred from SPI but not API.
1 parent eca1cf9 commit 422e4cd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/Sema/superfluously-public-imports.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
// RUN: %target-swift-frontend -emit-module %t/ImportNotUseFromAPI.swift -o %t -I %t
2222
// RUN: %target-swift-frontend -emit-module %t/ImportUsedInPackage.swift -o %t -I %t
2323
// RUN: %target-swift-frontend -emit-module %t/ExportedUnused.swift -o %t -I %t
24+
// RUN: %target-swift-frontend -emit-module %t/SPIOnlyUsedInSPI.swift -o %t -I %t
2425

2526
/// Check diagnostics.
2627
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
27-
// RUN: -package-name pkg -Rmodule-api-import -swift-version 6 -verify
28+
// RUN: -package-name pkg -Rmodule-api-import -swift-version 6 -verify \
29+
// RUN: -experimental-spi-only-imports
2830
// RUN: %target-swift-frontend -typecheck %t/ClientOfClangModules.swift -I %t \
2931
// RUN: -package-name pkg -Rmodule-api-import -swift-version 6 -verify
3032
// RUN: %target-swift-frontend -typecheck %t/Client_Swift5.swift -I %t \
@@ -105,6 +107,9 @@ public func packageFunc() -> PackageType { return PackageType() }
105107

106108
//--- ExportedUnused.swift
107109

110+
//--- SPIOnlyUsedInSPI.swift
111+
public struct ToUseFromSPI {}
112+
108113
//--- Client_Swift5.swift
109114
/// No diagnostics should be raised on the implicit access level.
110115
import UnusedImport // expected-error {{ambiguous implicit access level for import of 'UnusedImport'; it is imported as 'public' elsewhere}}
@@ -137,6 +142,7 @@ public import ImportNotUseFromAPI // expected-warning {{public import of 'Import
137142
public import ImportUsedInPackage // expected-warning {{public import of 'ImportUsedInPackage' was not used in public declarations or inlinable code}} {{1-7=package}}
138143

139144
@_exported public import ExportedUnused
145+
@_spiOnly public import SPIOnlyUsedInSPI
140146

141147
public func useInSignature(_ a: TypeUsedInSignature) {} // expected-remark {{struct 'TypeUsedInSignature' is imported via 'DepUsedInSignature'}}
142148
public func exportedTypeUseInSignature(_ a: ExportedType) {} // expected-remark {{struct 'ExportedType' is imported via 'Exporter', which reexports definition from 'Exportee'}}
@@ -219,6 +225,9 @@ func implicitlyInternalFunc(a: NotAnAPIType = notAnAPIFunc()) {}
219225
// For package decls we only remark on types used in signatures, not for inlinable code.
220226
package func packageFunc(a: PackageType = packageFunc()) {} // expected-remark {{struct 'PackageType' is imported via 'ImportUsedInPackage'}}
221227

228+
@_spi(X)
229+
public func spiFunc(a: ToUseFromSPI) {} // expected-remark {{struct 'ToUseFromSPI' is imported via 'SPIOnlyUsedInSPI'}}
230+
222231
/// Tests for imports of clang modules.
223232
//--- module.modulemap
224233
module ClangSimpleUnused {

0 commit comments

Comments
 (0)