Skip to content

Commit 242d01c

Browse files
committed
[Sema] Add test for references to restricted imports from frozen structs
Exporting types imported as non-public in @Frozen strucs is reported by pre-existing mechanics using the access-levels system. This simply adds a test to prevent regressions.
1 parent 5b8553c commit 242d01c

File tree

1 file changed

+97
-9
lines changed

1 file changed

+97
-9
lines changed

test/Sema/access-level-import-inlinable.swift

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// Test use of decls restricted by an import access-level in inlinable code.
1+
// Test use of decls restricted by an import access-level in inlinable code
2+
// and frozen structs.
23

34
// RUN: %empty-directory(%t)
45
// RUN: split-file %s %t
56

67
/// Build the libraries.
78
// RUN: %target-swift-frontend -emit-module %t/PublicLib.swift -o %t \
8-
// RUN: -enable-library-evolution
9+
// RUN: -swift-version 5 -enable-library-evolution
910
// RUN: %target-swift-frontend -emit-module %t/PackageLib.swift -o %t \
10-
// RUN: -enable-library-evolution
11+
// RUN: -swift-version 5 -enable-library-evolution
1112
// RUN: %target-swift-frontend -emit-module %t/InternalLib.swift -o %t \
12-
// RUN: -enable-library-evolution
13+
// RUN: -swift-version 5 -enable-library-evolution
1314
// RUN: %target-swift-frontend -emit-module %t/FileprivateLib.swift -o %t \
14-
// RUN: -enable-library-evolution
15+
// RUN: -swift-version 5 -enable-library-evolution
1516
// RUN: %target-swift-frontend -emit-module %t/PrivateLib.swift -o %t \
16-
// RUN: -enable-library-evolution
17+
// RUN: -swift-version 5 -enable-library-evolution
1718

1819
/// Check diagnostics.
1920
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
@@ -52,6 +53,8 @@ public struct InternalImportType {
5253
}
5354
public func InternalFunc() {}
5455

56+
@frozen public struct InternalImportFrozenType {}
57+
5558
//--- FileprivateLib.swift
5659
public protocol FileprivateImportProto {
5760
associatedtype T
@@ -74,20 +77,21 @@ public struct PrivateImportType {
7477
public import PublicLib
7578

7679
package import PackageLib
77-
// expected-note@-1 2 {{struct 'PackageImportType' imported as 'package' from 'PackageLib' here}}
80+
// expected-note@-1 4 {{struct 'PackageImportType' imported as 'package' from 'PackageLib' here}}
7881

7982
internal import InternalLib
80-
// expected-note@-1 6 {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
83+
// expected-note@-1 9 {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
8184
// expected-note@-2 4 {{protocol 'InternalImportProto' imported as 'internal' from 'InternalLib' here}}
8285
// expected-note@-3 2 {{global function 'InternalFunc()' imported as 'internal' from 'InternalLib' here}}
86+
// expected-note@-4 2 {{struct 'InternalImportFrozenType' imported as 'internal' from 'InternalLib' here}}
8387

8488
fileprivate import FileprivateLib
8589
// expected-note@-1 2 {{generic struct 'FileprivateImportWrapper' imported as 'fileprivate' from 'FileprivateLib' here}}
8690
// expected-note@-2 2 {{initializer 'init(wrappedValue:)' imported as 'fileprivate' from 'FileprivateLib' here}}
8791
// expected-note@-3 2 {{protocol 'FileprivateImportProto' imported as 'fileprivate' from 'FileprivateLib' here}}
8892

8993
private import PrivateLib
90-
// expected-note@-1 4 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
94+
// expected-note@-1 10 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
9195
// expected-note@-2 2 {{initializer 'init()' imported as 'private' from 'PrivateLib' here}}
9296

9397
public struct GenericType<T, U> {}
@@ -171,3 +175,87 @@ public struct GenericType<T, U> {}
171175
let _: GenericType<InternalImportType, PrivateImportType> // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
172176
// expected-error @-1 {{struct 'PrivateImportType' is private and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
173177
}
178+
179+
@frozen public struct BadFields1 {
180+
private var field: PrivateImportType // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
181+
}
182+
183+
@_fixed_layout public struct FixedBadFields1 {
184+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
185+
private var field: PrivateImportType // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
186+
}
187+
188+
@frozen public struct BadFields2 {
189+
private var field: PrivateImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
190+
}
191+
192+
@_fixed_layout public struct FixedBadFields2 {
193+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
194+
private var field: PrivateImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
195+
}
196+
197+
@frozen public struct BadFields3 {
198+
internal var field: PackageImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
199+
}
200+
201+
@_fixed_layout public struct FixedBadFields3 {
202+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
203+
internal var field: PackageImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
204+
}
205+
206+
@frozen @usableFromInline struct BadFields4 {
207+
internal var field: InternalImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
208+
}
209+
210+
@_fixed_layout @usableFromInline struct FixedBadFields4 {
211+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
212+
internal var field: InternalImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
213+
}
214+
215+
@frozen public struct BadFields5 {
216+
private var field: PrivateImportType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
217+
didSet {}
218+
}
219+
}
220+
221+
@_fixed_layout public struct FixedBadFields5 {
222+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
223+
private var field: PrivateImportType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
224+
didSet {}
225+
}
226+
}
227+
228+
@frozen public struct BadFields6 {
229+
private var field: InternalImportFrozenType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
230+
didSet {}
231+
}
232+
}
233+
234+
@_fixed_layout public struct FixedBadFields6 {
235+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
236+
private var field: InternalImportFrozenType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
237+
didSet {}
238+
}
239+
}
240+
241+
// expected-error@+1 {{the result of a '@usableFromInline' function must be '@usableFromInline' or public}}
242+
@usableFromInline func notReallyUsableFromInline() -> InternalImportType? { return nil }
243+
@frozen public struct BadFields7 {
244+
private var field = notReallyUsableFromInline() // expected-error {{type referenced from a stored property with inferred type 'InternalImportType?' in a '@frozen' struct must be '@usableFromInline' or public}}
245+
}
246+
247+
@_fixed_layout public struct FrozenBadFields7 {
248+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
249+
private var field = notReallyUsableFromInline() // expected-error {{type referenced from a stored property with inferred type 'InternalImportType?' in a '@frozen' struct must be '@usableFromInline' or public}}
250+
}
251+
252+
@frozen public struct OKFields {
253+
internal static var staticProp: InternalImportType?
254+
private var computed: PrivateImportType? { return nil }
255+
}
256+
257+
@_fixed_layout public struct FixedOKFields {
258+
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
259+
internal static var staticProp: InternalImportType?
260+
private var computed: PrivateImportType? { return nil }
261+
}

0 commit comments

Comments
 (0)