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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
struct NoTypecheck {
static let int: Int = 0
static func fatalError() -> Never { Swift.fatalError() }
}
protocol NoTypecheckProto {}
extension NoTypecheck: PublicProto {
func req() -> Int { return 0 }
}
// MARK: - Global functions
public func publicFunc() -> Int {
return NoTypecheck.int
}
public func publicFuncReturnsTypealias() -> PublicIntAlias {
return NoTypecheck.int
}
public func publicFuncWithDefaultArg(_ x: Int = 1) -> Int {
return NoTypecheck.int
}
package func packageFunc() -> Int {
return NoTypecheck.int
}
func internalFunc() -> NoTypecheck {
return NoTypecheck()
}
@inlinable func inlinableFunc() -> Int {
return 1
}
private func privateFunc() -> NoTypecheck {
return NoTypecheck()
}
public func constrainedGenericPublicFunction<T>(_ t: T) where T: PublicProto {
_ = NoTypecheck()
}
@_specialize(exported: true, where T == PublicProto)
public func publicSpecializedFunc<T>(_ t: T) -> T {
_ = NoTypecheck()
return t
}
@available(SwiftStdlib 5.1, *)
public func publicFuncWithOpaqueReturnType() -> some PublicProto {
return NoTypecheck()
}
@available(SwiftStdlib 5.1, *)
@_alwaysEmitIntoClient public func publicAEICFuncWithOpaqueReturnType() -> some Any {
if #available(macOS 20, *) {
return 3
} else {
return "hi"
}
}
// MARK: - Property wrappers
@propertyWrapper
public struct PublicWrapper<T> {
public var wrappedValue: T {
get {
NoTypecheck.fatalError()
}
set {
NoTypecheck.fatalError()
}
}
public var projectedValue: PublicWrapper { self }
public init(wrappedValue value: T) {
NoTypecheck.fatalError()
}
}
@propertyWrapper
struct InternalWrapper {
var wrappedValue: NoTypecheck
}
// MARK: - Global vars
public var publicGlobalVar: Int = NoTypecheck.int
public var publicGlobalVarTypealias: PublicIntAlias = 1
public var publicGlobalVarInferredType = ""
public var publicGlobalVarInferredInferredGeneric: [_] = [1]
public var publicGlobalVarTypealiasGeneric: PublicIntAlias? = 1
public var (publicGlobalVarInferredTuplePatX, publicGlobalVarInferredTuplePatY) = (0, 1)
var internalGlobalVar: NoTypecheck = NoTypecheck()
var internalGlobalVarInferredType = NoTypecheck()
var internalGlobalTypealiasVar: PublicIntAlias = NoTypecheck.int
// MARK: - Nominal types
public protocol EmptyPublicProto {}
public protocol PublicProto {
func req() -> Int
}
public protocol PublicProtoWithAssociatedType {
associatedtype A
func req() -> A
}
@rethrows public protocol PublicRethrowsProto {
func req() throws -> Int
}
@MainActor public protocol MainActorProtocol {
func req() throws -> Int
}
extension MainActorProtocol {
public func req() throws -> Int {
return 1
}
}
protocol InternalProtoWithAssociatedType {
associatedtype A
func internalReq() -> A
}
protocol InternalProtoConformingToPublicProto: PublicProto {
func internalReq() -> NoTypecheck
}
public struct PublicStruct {
public var publicProperty: Int = NoTypecheck.int
public var publicTypealiasProperty: PublicIntAlias = 1
public var publicPropertyInferredType = ""
public var publicLazyProperty: Int = NoTypecheck.int
public var publicLazyPropertyInferred = 1
@PublicWrapper public var publicWrappedProperty = 3.14
@_transparent public var publicTransparentProperty: Int {
get { return 1 }
}
public dynamic var publicDynamicProperty: Int = 5
public static let publicStaticProperty: Int = NoTypecheck.int
public static let publicStaticPropertyInferred = 2
public init(x: Int) {
_ = NoTypecheck()
}
public func publicMethod() -> Int {
return NoTypecheck.int
}
@MainActor public func publicMainActorMethod() -> Int {
return NoTypecheck.int
}
public static func publicStaticMethod() {
_ = NoTypecheck()
}
func internalMethod() -> NoTypecheck {
return NoTypecheck()
}
static func internalStaticMethod() -> NoTypecheck {
return NoTypecheck()
}
}
public struct PublicGenericStruct<T> {
var t: T
public func publicMethod() -> T {
_ = NoTypecheck()
return t
}
}
@frozen public struct FrozenPublicStruct {
private(set) var varWithPrivateSetter: Int = 1
public init(_ varWithPrivateSetter: Int) {
self.varWithPrivateSetter = varWithPrivateSetter
}
}
struct InternalStruct: NoTypecheckProto {
var x: NoTypecheck
func f(_ x: NoTypecheck) {}
}
public class PublicClass {
public var publicProperty: Int = NoTypecheck.int
public var publicPropertyInferredType = ""
public var publicLazyProperty: Int = NoTypecheck.int
public var publicLazyPropertyInferred = 1
@PublicWrapper public final var publicFinalWrappedProperty: Bool = false
public static let publicStaticProperty: Int = NoTypecheck.int
public static let publicStaticPropertyInferred = 2
public init(x: Int) {
self.publicProperty = x
_ = NoTypecheck()
}
convenience init(_ x: NoTypecheck) {
NoTypecheck.fatalError()
}
public func publicMethod() -> Int {
return NoTypecheck.int
}
public class func publicClassMethod() {
_ = NoTypecheck()
}
public static func publicStaticMethod() {
_ = NoTypecheck()
}
func internalMethod() -> NoTypecheck {
return NoTypecheck()
}
class func internalClassMethod() -> NoTypecheck {
return NoTypecheck()
}
}
public class PublicDerivedClass: PublicClass {}
open class PublicClassSynthesizedDesignatedInit {}
class InternalClass: NoTypecheckProto {
init(x: NoTypecheck) {}
}
public enum PublicEnum {
case a
case b(x: Int)
public func publicMethod() -> Int {
return NoTypecheck.int
}
public var publicComputedVar: Int {
return NoTypecheck.int
}
}
enum InternalEnum {
case bad(NoTypecheck)
func method() -> NoTypecheck {
return NoTypecheck()
}
}
// MARK: - Conformances
public struct PublicStructConformingToPublicProto: PublicProto {
public init() {}
public func req() -> Int {
return NoTypecheck.int
}
}
public struct PublicStructIndirectlyConformingToPublicProto: InternalProtoConformingToPublicProto {
public init() {}
public func req() -> Int {
return NoTypecheck.int
}
func internalReq() -> NoTypecheck {
return NoTypecheck()
}
}
public class PublicClassConformingToPublicProto: PublicProto {
public init() {}
public func req() -> Int {
return NoTypecheck.int
}
}
public class PublicClassInheritingConformanceToPublicProto: PublicClassConformingToPublicProto {}
extension String: PublicProto {
public func req() -> Int {
return NoTypecheck.int
}
}
extension String: InternalProtoWithAssociatedType {
func internalReq() -> NoTypecheck {
return NoTypecheck()
}
}
extension Int: PublicRethrowsProto {
public func req() throws -> Int {
return NoTypecheck.int
}
}
struct InternalStructConformingToPublicProto: PublicProtoWithAssociatedType {
typealias A = NoTypecheck
func req() -> A {
return NoTypecheck()
}
}
extension InternalStruct: PublicProtoWithAssociatedType {
typealias A = NoTypecheck
func req() -> A {
return NoTypecheck()
}
}
struct InternalStructConformingToInternalProto: InternalProtoWithAssociatedType {
func internalReq() -> NoTypecheck {
return NoTypecheck()
}
}
struct InternalStructForConstraint {}
extension PublicGenericStruct where T == InternalStructForConstraint {}
extension PublicGenericStruct: EmptyPublicProto where T == InternalStructForConstraint {}
// MARK: - Type aliases
public typealias PublicIntAlias = Int
public typealias PublicStructAlias = PublicStruct
typealias InternalTypeAlias = NoTypecheck
// MARK: - Compiler directives
extension PublicStruct {
#if FLAG
public static func activeMethod() {}
#else
public static func inactiveMethod() -> NoTypecheck {}
#endif
}
// MARK: - Operators & Precedence Groups
precedencegroup FooPrecedence {
assignment: true
associativity: right
}
infix operator <<<: FooPrecedence
extension PublicStruct {
public static func <<<(lhs: inout Self, rhs: Self) {
lhs = rhs
}
}
|