Skip to content

Commit 627b8f9

Browse files
committed
Sema: Test @Frozen struct in hidden-memory-layout.swift
1 parent 6d4c516 commit 627b8f9

File tree

1 file changed

+79
-16
lines changed

1 file changed

+79
-16
lines changed

test/Sema/hidden-memory-layout.swift

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public struct ExposedLayoutPublic {
7272
}
7373

7474
internal struct ExposedLayoutInternal {
75-
// expected-note @-1 {{type declared here}}
75+
// expected-note @-1 2 {{type declared here}}
7676
}
7777

7878
private struct ExposedLayoutPrivate {
7979
// expected-note @-1 2 {{struct 'ExposedLayoutPrivate' is not '@usableFromInline' or public}}
80-
// expected-note @-2 2 {{type declared here}}
80+
// expected-note @-2 3 {{type declared here}}
8181
init() { fatalError() } // expected-note {{initializer 'init()' is not '@usableFromInline' or public}}
8282
}
8383

@@ -86,12 +86,12 @@ public class ExposedClassPublic {
8686
}
8787

8888
internal class ExposedClassInternal {
89-
// expected-note @-1 {{type declared here}}
89+
// expected-note @-1 2 {{type declared here}}
9090
}
9191

9292
private class ExposedClassPrivate {
9393
// expected-note @-1 2 {{class 'ExposedClassPrivate' is not '@usableFromInline' or public}}
94-
// expected-note @-2 2 {{type declared here}}
94+
// expected-note @-2 3 {{type declared here}}
9595
init() { fatalError() } // expected-note {{initializer 'init()' is not '@usableFromInline' or public}}
9696
}
9797

@@ -100,14 +100,14 @@ private class ExposedClassPrivate {
100100
private class HiddenClass {
101101
// expected-opt-in-note @-1 2 {{class 'HiddenClass' is not '@usableFromInline' or public}}
102102
// expected-opt-in-note @-2 1 {{initializer 'init()' is not '@usableFromInline' or public}}
103-
// expected-opt-in-note @-3 6 {{class declared here}}
104-
// expected-opt-in-note @-4 2 {{type declared here}}
103+
// expected-opt-in-note @-3 7 {{class declared here}}
104+
// expected-opt-in-note @-4 3 {{type declared here}}
105105
}
106106
#else
107107
private class HiddenClass {
108108
// expected-not-opt-in-note @-1 2 {{class 'HiddenClass' is not '@usableFromInline' or public}}
109109
// expected-not-opt-in-note @-2 1 {{initializer 'init()' is not '@usableFromInline' or public}}
110-
// expected-not-opt-in-note @-3 2 {{type declared here}}
110+
// expected-not-opt-in-note @-3 3 {{type declared here}}
111111
}
112112
#endif
113113

@@ -116,14 +116,14 @@ private class HiddenClass {
116116
private struct HiddenLayout {
117117
// expected-opt-in-note @-1 2 {{struct 'HiddenLayout' is not '@usableFromInline' or public}}
118118
// expected-opt-in-note @-2 1 {{initializer 'init()' is not '@usableFromInline' or public}}
119-
// expected-opt-in-note @-3 9 {{struct declared here}}
120-
// expected-opt-in-note @-4 2 {{type declared here}}
119+
// expected-opt-in-note @-3 10 {{struct declared here}}
120+
// expected-opt-in-note @-4 3 {{type declared here}}
121121
}
122122
#else
123123
private struct HiddenLayout {
124124
// expected-not-opt-in-note @-1 2 {{struct 'HiddenLayout' is not '@usableFromInline' or public}}
125125
// expected-not-opt-in-note @-2 1 {{initializer 'init()' is not '@usableFromInline' or public}}
126-
// expected-not-opt-in-note @-3 2 {{type declared here}}
126+
// expected-not-opt-in-note @-3 3 {{type declared here}}
127127
}
128128
#endif
129129

@@ -134,6 +134,7 @@ public enum ExposedEnumPublic {
134134

135135
private enum ExposedEnumPrivate {
136136
// expected-note @-1 2 {{enum 'ExposedEnumPrivate' is not '@usableFromInline' or public}}
137+
// expected-note @-2 {{type declared here}}
137138
case A
138139
// expected-note @-1 1 {{enum case 'A' is not '@usableFromInline' or public}}
139140
case B
@@ -142,15 +143,17 @@ private enum ExposedEnumPrivate {
142143
#if UseImplementationOnly
143144
@_implementationOnly
144145
private enum HiddenEnum {
145-
// expected-opt-in-note @-1 6 {{enum declared here}}
146+
// expected-opt-in-note @-1 7 {{enum declared here}}
146147
// expected-opt-in-note @-2 2 {{enum 'HiddenEnum' is not '@usableFromInline' or public}}
148+
// expected-opt-in-note @-3 {{type declared here}}
147149
case A
148150
// expected-opt-in-note @-1 {{enum case 'A' is not '@usableFromInline' or public}}
149151
case B
150152
}
151153
#else
152154
private enum HiddenEnum {
153155
// expected-not-opt-in-note @-1 2 {{enum 'HiddenEnum' is not '@usableFromInline' or public}}
156+
// expected-not-opt-in-note @-2 {{type declared here}}
154157
case A
155158
// expected-not-opt-in-note @-1 {{enum case 'A' is not '@usableFromInline' or public}}
156159
case B
@@ -162,28 +165,31 @@ public protocol ExposedProtocolPublic {
162165

163166
internal protocol ExposedProtocolInternal {
164167
// expected-note @-1 {{protocol 'ExposedProtocolInternal' is not '@usableFromInline' or public}}
165-
// expected-note @-2 {{type declared here}}
168+
// expected-note @-2 2 {{type declared here}}
166169
}
167170

168171
private protocol ExposedProtocolPrivate {
169172
// expected-note @-1 {{protocol 'ExposedProtocolPrivate' is not '@usableFromInline' or public}}
170-
// expected-note @-2 2 {{type declared here}}
173+
// expected-note @-2 3 {{type declared here}}
171174
}
172175

173176
#if UseImplementationOnly
174177
@_implementationOnly
175178
private protocol HiddenProtocol {
176179
// expected-opt-in-note @-1 {{protocol 'HiddenProtocol' is not '@usableFromInline' or public}}
177-
// expected-opt-in-note @-2 9 {{protocol declared here}}
178-
// expected-opt-in-note @-3 2 {{type declared here}}
180+
// expected-opt-in-note @-2 10 {{protocol declared here}}
181+
// expected-opt-in-note @-3 3 {{type declared here}}
179182
}
180183
#else
181184
private protocol HiddenProtocol {
182185
// expected-not-opt-in-note @-1 1 {{protocol 'HiddenProtocol' is not '@usableFromInline' or public}}
183-
// expected-not-opt-in-note @-2 2 {{type declared here}}
186+
// expected-not-opt-in-note @-2 3 {{type declared here}}
184187
}
185188
#endif
186189

190+
@_spi(S) public struct SPIStruct {}
191+
// expected-note @-1 {{struct declared here}}
192+
187193
/// Function use sites
188194

189195
@inlinable
@@ -311,6 +317,63 @@ internal func explicitNonInliableInternal() {
311317

312318
/// Struct use sites
313319

320+
@frozen
321+
public struct ExposedLayoutFrozenUser: ProtocolFromDirect {
322+
// expected-error @-1 {{cannot use protocol 'ProtocolFromDirect' in a public or '@usableFromInline' conformance; 'directs' has been imported as implementation-only}}
323+
324+
public var publicField: StructFromDirect
325+
// expected-error @-1 {{cannot use struct 'StructFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}}
326+
327+
private var privateField: StructFromDirect
328+
// expected-error @-1 {{cannot use struct 'StructFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}}
329+
330+
private var a: ExposedLayoutPublic
331+
private var aa: ExposedLayoutInternal
332+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
333+
private var b: ExposedLayoutPrivate
334+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
335+
private var c: HiddenLayout
336+
// expected-opt-in-error @-1 {{cannot use struct 'HiddenLayout' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'HiddenLayout' is marked '@_implementationOnly'}}
337+
// expected-error @-2 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
338+
339+
private var ca: ExposedClassPublic
340+
private var cb: ExposedClassInternal
341+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
342+
private var cc: ExposedClassPrivate
343+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
344+
private var cd: HiddenClass
345+
// expected-opt-in-error @-1 {{cannot use class 'HiddenClass' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'HiddenClass' is marked '@_implementationOnly'}}
346+
// expected-error @-2 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
347+
348+
private var d: ExposedEnumPublic
349+
private var e: ExposedEnumPrivate
350+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
351+
private var f: HiddenEnum
352+
// expected-opt-in-error @-1 {{cannot use enum 'HiddenEnum' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'HiddenEnum' is marked '@_implementationOnly'}}
353+
// expected-error @-2 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
354+
355+
private var pp: ProtocolFromDirect
356+
// expected-error @-1 {{cannot use protocol 'ProtocolFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}}
357+
358+
private var g: ExposedProtocolPublic
359+
private var h: ExposedProtocolInternal
360+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
361+
private var i: ExposedProtocolPrivate
362+
// expected-error @-1 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
363+
private var j: HiddenProtocol
364+
// expected-opt-in-error @-1 {{cannot use protocol 'HiddenProtocol' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'HiddenProtocol' is marked '@_implementationOnly'}}
365+
// expected-error @-2 {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
366+
367+
private func privateFunc(h: HiddenLayout) {}
368+
// expected-embedded-opt-in-error @-1 {{struct 'HiddenLayout' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenLayout' is marked '@_implementationOnly'}}
369+
private func privateFuncClass(h: HiddenClass) {}
370+
// expected-embedded-opt-in-error @-1 {{class 'HiddenClass' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenClass' is marked '@_implementationOnly'}}
371+
372+
@_spi(S) public var s: SPIStruct
373+
// expected-error @-1 {{stored property 's' cannot be declared '@_spi' in a '@frozen' struct}}
374+
// expected-error @-2 {{cannot use struct 'SPIStruct' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
375+
}
376+
314377
public struct ExposedLayoutPublicUser: ProtocolFromDirect {
315378
// expected-error @-1 {{cannot use protocol 'ProtocolFromDirect' in a public or '@usableFromInline' conformance; 'directs' has been imported as implementation-only}}
316379

0 commit comments

Comments
 (0)