1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
// Test use of decls restricted by an import access-level in inlinable code
// and frozen structs.
// RUN: %empty-directory(%t)
// RUN: split-file %s %t --leading-lines
/// Build the libraries.
// RUN: %target-swift-frontend -emit-module %t/PublicLib.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/PackageLib.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/InternalLib.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/FileprivateLib.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/PrivateLib.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
/// Check diagnostics.
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -enable-library-evolution -swift-version 5 -verify \
// RUN: -package-name package
//--- PublicLib.swift
public protocol PublicImportProto {
associatedtype T
}
public struct PublicImportType {
public init() {}
}
public func PublicFunc() {}
@propertyWrapper
public struct PublicImportWrapper<T> {
public var wrappedValue: T
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
}
//--- PackageLib.swift
public struct PackageImportType {
public init() {}
}
//--- InternalLib.swift
public protocol InternalImportProto {
associatedtype T
}
public struct InternalImportType {
public init() {}
}
public func InternalFunc() {}
@frozen public struct InternalImportFrozenType {}
//--- FileprivateLib.swift
public protocol FileprivateImportProto {
associatedtype T
}
@propertyWrapper
public struct FileprivateImportWrapper<T> {
public var wrappedValue: T
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
}
//--- PrivateLib.swift
public struct PrivateImportType {
public init() {}
}
//--- Client.swift
public import PublicLib
package import PackageLib
// expected-note@-1 4 {{struct 'PackageImportType' imported as 'package' from 'PackageLib' here}}
internal import InternalLib
// expected-note@-1 9 {{struct 'InternalImportType' imported as 'internal' from 'InternalLib' here}}
// expected-note@-2 4 {{protocol 'InternalImportProto' imported as 'internal' from 'InternalLib' here}}
// expected-note@-3 2 {{global function 'InternalFunc()' imported as 'internal' from 'InternalLib' here}}
// expected-note@-4 2 {{struct 'InternalImportFrozenType' imported as 'internal' from 'InternalLib' here}}
fileprivate import FileprivateLib
// expected-note@-1 2 {{generic struct 'FileprivateImportWrapper' imported as 'fileprivate' from 'FileprivateLib' here}}
// expected-note@-2 2 {{initializer 'init(wrappedValue:)' imported as 'fileprivate' from 'FileprivateLib' here}}
// expected-note@-3 2 {{protocol 'FileprivateImportProto' imported as 'fileprivate' from 'FileprivateLib' here}}
private import PrivateLib
// expected-note@-1 10 {{struct 'PrivateImportType' imported as 'private' from 'PrivateLib' here}}
// expected-note@-2 2 {{initializer 'init()' imported as 'private' from 'PrivateLib' here}}
public struct GenericType<T, U> {}
@inlinable public func inlinable() {
PublicFunc()
InternalFunc() // expected-error {{global function 'InternalFunc()' is internal and cannot be referenced from an '@inlinable' function}}
let _: PublicImportType
let _: InternalImportType // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@inlinable' function}}
let _ = PublicImportType()
let _ = PrivateImportType() // expected-error {{struct 'PrivateImportType' is private and cannot be referenced from an '@inlinable' function}}
// expected-error @-1 {{initializer 'init()' is private and cannot be referenced from an '@inlinable' function}}
let _: any PublicImportProto
let _: any InternalImportProto // expected-error {{protocol 'InternalImportProto' is internal and cannot be referenced from an '@inlinable' function}}
let _: any FileprivateImportProto & InternalImportProto // expected-error {{protocol 'FileprivateImportProto' is fileprivate and cannot be referenced from an '@inlinable' function}}
// expected-error @-1 {{protocol 'InternalImportProto' is internal and cannot be referenced from an '@inlinable' function}}
func PublicFuncUsesPublic(_: PublicImportType) {}
func PublicFuncUsesPackage(_: PackageImportType) {} // expected-error {{struct 'PackageImportType' is package and cannot be referenced from an '@inlinable' function}}}
func PublicFuncUsesPublic() -> PublicImportType {
fatalError()
}
func PublicFuncReturnUsesInternal() -> InternalImportType { // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@inlinable' function}}
fatalError()
}
@PublicImportWrapper
var wrappedPublic: PublicImportType
@FileprivateImportWrapper // expected-error {{initializer 'init(wrappedValue:)' is fileprivate and cannot be referenced from an '@inlinable' function}}
// expected-error @-1 {{generic struct 'FileprivateImportWrapper' is fileprivate and cannot be referenced from an '@inlinable' function}}
var wrappedFileprivate: PublicImportType
let _: GenericType<PublicImportType, PublicImportType>
let _: GenericType<InternalImportType, PrivateImportType> // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@inlinable' function}}
// expected-error @-1 {{struct 'PrivateImportType' is private and cannot be referenced from an '@inlinable' function}}
}
@_alwaysEmitIntoClient public func alwaysEmitIntoClient() {
PublicFunc()
InternalFunc() // expected-error {{global function 'InternalFunc()' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
let _: PublicImportType
let _: InternalImportType // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
let _ = PublicImportType()
let _ = PrivateImportType() // expected-error {{struct 'PrivateImportType' is private and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
// expected-error @-1 {{initializer 'init()' is private and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
let _: any PublicImportProto
let _: any InternalImportProto // expected-error {{protocol 'InternalImportProto' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
let _: any FileprivateImportProto & InternalImportProto // expected-error {{protocol 'FileprivateImportProto' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
// expected-error @-1 {{protocol 'InternalImportProto' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
func PublicFuncUsesPublic(_: PublicImportType) {}
func PublicFuncUsesPackage(_: PackageImportType) {} // expected-error {{struct 'PackageImportType' is package and cannot be referenced from an '@_alwaysEmitIntoClient' function}}}
func PublicFuncUsesPublic() -> PublicImportType {
fatalError()
}
func PublicFuncReturnUsesInternal() -> InternalImportType { // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
fatalError()
}
@PublicImportWrapper
var wrappedPublic: PublicImportType
@FileprivateImportWrapper // expected-error {{initializer 'init(wrappedValue:)' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
// expected-error @-1 {{generic struct 'FileprivateImportWrapper' is fileprivate and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
var wrappedFileprivate: PublicImportType
let _: GenericType<PublicImportType, PublicImportType>
let _: GenericType<InternalImportType, PrivateImportType> // expected-error {{struct 'InternalImportType' is internal and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
// expected-error @-1 {{struct 'PrivateImportType' is private and cannot be referenced from an '@_alwaysEmitIntoClient' function}}
}
@frozen public struct BadFields1 {
private var field: PrivateImportType // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
}
@_fixed_layout public struct FixedBadFields1 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
private var field: PrivateImportType // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
}
@frozen public struct BadFields2 {
private var field: PrivateImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
}
@_fixed_layout public struct FixedBadFields2 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
private var field: PrivateImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
}
@frozen public struct BadFields3 {
internal var field: PackageImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PackageImportType' is imported by this file as 'package' from 'PackageLib'}}
}
@_fixed_layout public struct FixedBadFields3 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
internal var field: PackageImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PackageImportType' is imported by this file as 'package' from 'PackageLib'}}
}
@frozen @usableFromInline struct BadFields4 {
internal var field: InternalImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'InternalImportType' is imported by this file as 'internal' from 'InternalLib'}}
}
@_fixed_layout @usableFromInline struct FixedBadFields4 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
internal var field: InternalImportType? // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'InternalImportType' is imported by this file as 'internal' from 'InternalLib'}}
}
@frozen public struct BadFields5 {
private var field: PrivateImportType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
didSet {}
}
}
@_fixed_layout public struct FixedBadFields5 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
private var field: PrivateImportType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'PrivateImportType' is imported by this file as 'private' from 'PrivateLib'}}
didSet {}
}
}
@frozen public struct BadFields6 {
private var field: InternalImportFrozenType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'InternalImportFrozenType' is imported by this file as 'internal' from 'InternalLib'}}
didSet {}
}
}
@_fixed_layout public struct FixedBadFields6 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
private var field: InternalImportFrozenType? { // expected-error {{type referenced from a stored property in a '@frozen' struct must be '@usableFromInline' or public}}
// expected-note @-1 {{struct 'InternalImportFrozenType' is imported by this file as 'internal' from 'InternalLib'}}
didSet {}
}
}
// expected-error@+1 {{the result of a '@usableFromInline' function must be '@usableFromInline' or public}}
@usableFromInline func notReallyUsableFromInline() -> InternalImportType? { return nil }
// expected-note @-1 {{struct 'InternalImportType' is imported by this file as 'internal' from 'InternalLib'}}
@frozen public struct BadFields7 {
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}}
}
@_fixed_layout public struct FrozenBadFields7 {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
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}}
}
@frozen public struct OKFields {
internal static var staticProp: InternalImportType?
private var computed: PrivateImportType? { return nil }
}
@_fixed_layout public struct FixedOKFields {
// expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}}
internal static var staticProp: InternalImportType?
private var computed: PrivateImportType? { return nil }
}
|