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
|
// RUN: %target-swift-frontend -print-ast -disable-objc-attr-requires-foundation-module -enable-objc-interop %s -diagnostic-style llvm 2>&1 | %FileCheck %s
var x = 0.0
type(of: x)
// CHECK: type(of: x)
class A {
var x: Int = 3
init() {
}
}
class B: A {
override init() {
super.init()
super.x = 2;
}
}
// CHECK: @_inheritsConvenienceInitializers internal class B : A {
// CHECK: override internal init() {
// CHECK: super.init()
// CHECK: super.x = 2
// CHECK: }
// CHECK: @objc deinit {
// CHECK: }
// CHECK: }
var a: [Int] = [1, 3, 2];
for i in 0...2 {
a[i] = i;
}
// CHECK: for i in 0 ... 2 {
// CHECK: a[i] = i
// CHECK: }
let y: Double = 0 as Double
// CHECK: @_hasInitialValue internal let y: Double = 0 as Double
var stringToInt: Int? = Int("1");
var forceInt: Int = stringToInt!
// CHECK: @_hasInitialValue internal var forceInt: Int = stringToInt!
var prefixUnaryExpr: Int = -a[1];
// CHECK: @_hasInitialValue internal var prefixUnaryExpr: Int = -a[1]
var postfixUnaryExpr: Int = stringToInt!
// CHECK: @_hasInitialValue internal var postfixUnaryExpr: Int = stringToInt!
class MyID {
var num = 1
}
class SomeJSON {
var id: MyID?
}
let cnt = SomeJSON().id?.num
// CHECK: @_hasInitialValue internal let cnt: Int? = SomeJSON().id?.num
struct User {
let name: String
let email: String
let address: Address?
let role: Role
}
struct Address {
let street: String
}
enum Role {
case admin
case member
case guest
var permissions: [Permission] {
switch self {
case .admin:
return [.create, .read, .update, .delete]
case .member:
return [.create, .read]
case .guest:
return [.read]
}
}
}
enum Permission {
case create
case read
case update
case delete
}
var user = User(
name: "Swift",
email: "http://www.swift.org",
address: nil,
role: .admin
)
let userRoleKeyPath = \User.role
// CHECK: @_hasInitialValue internal let userRoleKeyPath: KeyPath<User, Role> = \User
let role = user[keyPath: userRoleKeyPath]
// CHECK: @_hasInitialValue internal let role: Role = user[keyPath: userRoleKeyPath]
struct FakeColor: _ExpressibleByColorLiteral {
init(_colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {}
}
typealias _ColorLiteralType = FakeColor
let myColor = #colorLiteral(red: 0.292, green: 0.081, blue: 0.6, alpha: 255)
// CHECK: @_hasInitialValue internal let myColor: FakeColor = #colorLiteral(red: 0.292, green: 0.081, blue: 0.6, alpha: 255)
enum FileNames {
static let main = FileNames.file(#file)
// CHECK: @_hasInitialValue internal static let main: FileNames = FileNames.file(#file)
case file(String)
}
class C {
@objc
var foo = 0
}
func foo(_ x: AnyObject) {
let y = x.foo
}
// CHECK: internal func foo(_ x: AnyObject) {
// CHECK: @_hasInitialValue let y: Int? = x.foo
// CHECK: }
struct S {
func foo() {}
}
let fn = S.foo
|