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
|
// RUN: %target-typecheck-verify-swift
@propertyWrapper
public struct Wrapper<T> {
public init(wrappedValue: T) {}
public var wrappedValue: T { fatalError() }
}
@_spi(Foo)
@propertyWrapper
public struct SPIWrapper<T> {
// expected-note@-1 2 {{generic struct declared here}}
public init(wrappedValue: T) {}
public var wrappedValue: T { fatalError() }
}
@_spi(Foo)
public class SPIType {
// expected-note@-1 16{{class declared here}}
public init() {}
}
public struct PublicType {
public init() {}
@_spi(Foo) public func spiFunc() {}
}
public struct ResilientStructSPIMembers {
public init() {}
@_spi(Foo) public func method(_: SPIType) {}
@_spi(Foo) public var computedProperty: SPIType { SPIType() }
@_spi(Foo) public var storedProperty1: SPIType
@_spi(Foo) public var storedProperty2 = SPIType()
@_spi(Foo) public lazy var lazyProperty1 = SPIType()
@_spi(Foo) public lazy var lazyProperty2: SPIType = SPIType()
@_spi(Foo) @Wrapper public var wrappedProperty1: SPIType
@_spi(Foo) @Wrapper public var wrappedProperty2 = SPIType()
@_spi(Foo) @SPIWrapper public var wrappedProperty3 = SPIType()
@SPIWrapper public var wrappedProperty4: PublicType
// expected-error@-1 {{cannot use generic struct 'SPIWrapper' as property wrapper here; it is SPI}}
@_spi(Foo) public var inlinableGet: Int {
@inlinable
get {
let _ = SPIType()
let t = PublicType()
t.spiFunc()
return 42
}
}
public var inlinablePublicGet: Int {
@inlinable
get {
let _ = SPIType()
// expected-error@-1 {{class 'SPIType' cannot be used in an '@inlinable' function because it is SPI}}
// expected-error@-2 {{initializer 'init()' cannot be used in an '@inlinable' function because it is SPI}}
let t = PublicType()
t.spiFunc()
// expected-error@-1 {{instance method 'spiFunc()' cannot be used in an '@inlinable' function because it is SPI}}
return 42
}
}
}
@frozen public struct FrozenStructSPIMembers {
public init() {}
@_spi(Foo) public func method(_: SPIType) {}
@_spi(Foo) public var computedProperty: SPIType { SPIType() }
@_spi(Foo) public var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{stored property 'storedProperty1' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) public var storedProperty2 = SPIType()
// expected-error@-1 {{stored property 'storedProperty2' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) public lazy var lazyProperty1 = SPIType()
// expected-error@-1 {{stored property 'lazyProperty1' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) public lazy var lazyProperty2: SPIType = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{stored property 'lazyProperty2' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) @Wrapper public var wrappedProperty1: SPIType
// expected-error@-1 {{stored property 'wrappedProperty1' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) @Wrapper public var wrappedProperty2 = SPIType()
// expected-error@-1 {{stored property 'wrappedProperty2' cannot be declared '@_spi' in a '@frozen' struct}}
@_spi(Foo) @SPIWrapper public var wrappedProperty3 = SPIType()
// expected-error@-1 {{stored property 'wrappedProperty3' cannot be declared '@_spi' in a '@frozen' struct}}
}
@frozen public struct FrozenStructPublicMembers {
public init() {}
public func method(_: SPIType) {} // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
public var storedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
public var computedProperty: SPIType { SPIType() } // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
@Wrapper public var wrappedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
@Wrapper public var wrappedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
@SPIWrapper public var wrappedProperty3: PublicType
// expected-error@-1 {{cannot use generic struct 'SPIWrapper' as property wrapper here; it is SPI}}
}
@frozen public struct FrozenStructPrivateMembers {
private init() {}
private func method(_: SPIType) {}
private var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
private var storedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
private var computedProperty: SPIType { SPIType() }
private lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
private lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
@Wrapper private var wrappedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
@Wrapper private var wrappedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
}
public enum ResilientEnum {
@_spi(S)
case okSpiCase
@_spi(S)
case okSpiCaseWithPayload(_: Int)
}
@frozen
public enum FrozenEnum {
case okCase
@_spi(S) // expected-error {{enum case 'spiCase' cannot be declared '@_spi' in a '@frozen' enum}}
case spiCase
case okCaseWithPayload(_: Int)
@_spi(S) // expected-error {{enum case 'spiCaseWithPayload' cannot be declared '@_spi' in a '@frozen' enum}}
case spiCaseWithPayload(_: Int)
}
|