-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathavailability_literals.swift
169 lines (140 loc) Β· 7.98 KB
/
availability_literals.swift
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
// RUN: %target-typecheck-verify-swift -swift-version 5 -print-diagnostic-groups
// REQUIRES: OS=macosx
// https://github.com/apple/swift/issues/61564
// ExpressibleByStringLiteral
struct SLD {}
@available(*, deprecated)
extension SLD: ExpressibleByStringLiteral {
init(stringLiteral value: StringLiteralType) {}
}
let _ = SLD(stringLiteral: "") // expected-warning{{'init(stringLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: SLD = "" // expected-warning{{'init(stringLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct SLU {}
@available(macOS 100, *)
extension SLU: ExpressibleByStringLiteral {
init(stringLiteral value: StringLiteralType) {}
}
let _ = SLU(stringLiteral: "") // expected-error{{'init(stringLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: SLU = "" // expected-error{{'init(stringLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByIntegerLiteral
struct ILD {}
@available(*, deprecated)
extension ILD: ExpressibleByIntegerLiteral {
init(integerLiteral value: IntegerLiteralType) {}
}
let _ = ILD(integerLiteral: 1) // expected-warning{{'init(integerLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: ILD = 1 // expected-warning{{'init(integerLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct ILU {}
@available(macOS 100, *)
extension ILU: ExpressibleByIntegerLiteral {
init(integerLiteral value: IntegerLiteralType) {}
}
let _ = ILU(integerLiteral: 1) // expected-error{{'init(integerLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: ILU = 1 // expected-error{{'init(integerLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByNilLiteral
struct NLD {}
@available(*, deprecated)
extension NLD: ExpressibleByNilLiteral {
init(nilLiteral: ()) {}
}
let _: NLD = .init(nilLiteral: ()) // expected-warning{{'init(nilLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: NLD = nil // expected-warning{{'init(nilLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct NLU {}
@available(macOS 100, *)
extension NLU: ExpressibleByNilLiteral {
init(nilLiteral: ()) {}
}
let _: NLU = .init(nilLiteral: ()) // expected-error{{'init(nilLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: NLU = nil // expected-error{{'init(nilLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByBooleanLiteral
struct BLD {}
@available(*, deprecated)
extension BLD: ExpressibleByBooleanLiteral {
init(booleanLiteral value: BooleanLiteralType) {}
}
let _: BLD = .init(booleanLiteral: false) // expected-warning{{'init(booleanLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: BLD = false // expected-warning{{'init(booleanLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct BLU {}
@available(macOS 100, *)
extension BLU: ExpressibleByBooleanLiteral {
init(booleanLiteral value: BooleanLiteralType) {}
}
let _: BLU = .init(booleanLiteral: false) // expected-error{{'init(booleanLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: BLU = false // expected-error{{'init(booleanLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByFloatLiteral
struct FLD {}
@available(*, deprecated)
extension FLD: ExpressibleByFloatLiteral {
init(floatLiteral value: FloatLiteralType) {}
}
let _: FLD = .init(floatLiteral: 0.1) // expected-warning{{'init(floatLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: FLD = 0.1 // expected-warning{{'init(floatLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct FLU {}
@available(macOS 100, *)
extension FLU: ExpressibleByFloatLiteral {
init(floatLiteral value: FloatLiteralType) {}
}
let _: FLU = .init(floatLiteral: 0.1) // expected-error{{'init(floatLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: FLU = 0.1 // expected-error{{'init(floatLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByArrayLiteral
struct ALD {}
@available(*, deprecated)
extension ALD: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Int...) {}
}
let _: ALD = .init(arrayLiteral: 1) // expected-warning{{'init(arrayLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: ALD = [1] // expected-warning{{'init(arrayLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct ALU {}
@available(macOS 100, *)
extension ALU: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Int...) {}
}
let _: ALU = .init(arrayLiteral: 1) // expected-error{{'init(arrayLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: ALU = [1] // expected-error{{'init(arrayLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByDictionaryLiteral
struct DLD {}
@available(*, deprecated)
extension DLD: ExpressibleByDictionaryLiteral {
init(dictionaryLiteral elements: (Int, Int)...) {}
}
let _: DLD = .init(dictionaryLiteral: (1,1)) // expected-warning{{'init(dictionaryLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: DLD = [1: 1] // expected-warning{{'init(dictionaryLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct DLU {}
@available(macOS 100, *)
extension DLU: ExpressibleByDictionaryLiteral {
init(dictionaryLiteral elements: (Int, Int)...) {}
}
let _: DLU = .init(dictionaryLiteral: (1,1)) // expected-error{{'init(dictionaryLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: DLU = [1: 1] // expected-error{{'init(dictionaryLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
// ExpressibleByUnicodeScalarLiteral
struct USLD {}
@available(*, deprecated)
extension USLD: ExpressibleByUnicodeScalarLiteral {
typealias UnicodeScalarLiteralType = Character
init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {}
}
let _: USLD = .init(unicodeScalarLiteral: "a") // expected-warning{{'init(unicodeScalarLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: USLD = "a" // expected-warning{{'init(unicodeScalarLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct USLU {}
@available(macOS 100, *)
extension USLU: ExpressibleByUnicodeScalarLiteral {
typealias UnicodeScalarLiteralType = Character
init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {}
}
let _: USLU = .init(unicodeScalarLiteral: "a") // expected-error{{'init(unicodeScalarLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: USLU = "a" // expected-error{{'init(unicodeScalarLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
//ExpressibleByExtendedGraphemeClusterLiteral
struct GCLD {}
@available(*, deprecated)
extension GCLD: ExpressibleByExtendedGraphemeClusterLiteral {
init(extendedGraphemeClusterLiteral value: Character) {}
}
let _: GCLD = .init(extendedGraphemeClusterLiteral: "π§π·") // expected-warning{{'init(extendedGraphemeClusterLiteral:)' is deprecated [DeprecatedDeclaration]}}
let _: GCLD = "π§π·" // expected-warning{{'init(extendedGraphemeClusterLiteral:)' is deprecated [DeprecatedDeclaration]}}
struct GCLU {}
@available(macOS 100, *)
extension GCLU: ExpressibleByExtendedGraphemeClusterLiteral {
init(extendedGraphemeClusterLiteral value: Character) {}
}
let _: GCLU = .init(extendedGraphemeClusterLiteral: "π§π·") // expected-error{{'init(extendedGraphemeClusterLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}
let _: GCLU = "π§π·" // expected-error{{'init(extendedGraphemeClusterLiteral:)' is only available in macOS 100 or newer}} expected-note{{add 'if #available' version check}}