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
|
// RUN: %target-typecheck-verify-swift -parse-as-library
// See also rdar://15626843.
static var gvu1: Int // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-2 {{add an initializer to silence this error}} {{18-18= = <#initializer#>}}
class var gvu2: Int // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-2 {{add an initializer to silence this error}} {{17-17= = <#initializer#>}}
override static var gvu3: Int // expected-error {{static properties may only be declared on a type}}{{10-17=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
// expected-error@-2 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-3 {{add an initializer to silence this error}} {{27-27= = <#initializer#>}}
override class var gvu4: Int // expected-error {{class properties may only be declared on a type}}{{10-16=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
// expected-error@-2 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-3 {{add an initializer to silence this error}} {{26-26= = <#initializer#>}}
static override var gvu5: Int // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{8-17=}}
// expected-error@-2 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-3 {{add an initializer to silence this error}} {{27-27= = <#initializer#>}}
class override var gvu6: Int // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{7-16=}}
// expected-error@-2 {{global 'var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-3 {{add an initializer to silence this error}} {{26-26= = <#initializer#>}}
static var gvu7: Int { // expected-error {{static properties may only be declared on a type}}{{1-8=}}
return 42
}
class var gvu8: Int { // expected-error {{class properties may only be declared on a type}}{{1-7=}}
return 42
}
static let glu1: Int // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{global 'let' declaration requires an initializer expression}}
// expected-note@-2 {{add an initializer to silence this error}} {{18-18= = <#initializer#>}}
class let glu2: Int // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{global 'let' declaration requires an initializer expression}}
// expected-note@-2 {{add an initializer to silence this error}} {{17-17= = <#initializer#>}}
override static let glu3: Int // expected-error {{static properties may only be declared on a type}}{{10-17=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
// expected-error@-2 {{global 'let' declaration requires an initializer expression}}
// expected-note@-3 {{add an initializer to silence this error}} {{27-27= = <#initializer#>}}
override class let glu4: Int // expected-error {{class properties may only be declared on a type}}{{10-16=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
// expected-error@-2 {{global 'let' declaration requires an initializer expression}}
// expected-note@-3 {{add an initializer to silence this error}} {{26-26= = <#initializer#>}}
static override let glu5: Int // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{8-17=}}
// expected-error@-2 {{global 'let' declaration requires an initializer expression}}
// expected-note@-3 {{add an initializer to silence this error}} {{27-27= = <#initializer#>}}
class override let glu6: Int // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{7-16=}}
// expected-error@-2 {{global 'let' declaration requires an initializer expression}}
// expected-note@-3 {{add an initializer to silence this error}} {{26-26= = <#initializer#>}}
static var gvi1: Int = 0 // expected-error {{static properties may only be declared on a type}}{{1-8=}}
class var gvi2: Int = 0 // expected-error {{class properties may only be declared on a type}}{{1-7=}}
override static var gvi3: Int = 0 // expected-error {{static properties may only be declared on a type}}{{10-17=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
override class var gvi4: Int = 0 // expected-error {{class properties may only be declared on a type}}{{10-16=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
static override var gvi5: Int = 0 // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{8-17=}}
class override var gvi6: Int = 0 // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{7-16=}}
static let gli1: Int = 0 // expected-error {{static properties may only be declared on a type}}{{1-8=}}
class let gli2: Int = 0 // expected-error {{class properties may only be declared on a type}}{{1-7=}}
override static let gli3: Int = 0 // expected-error {{static properties may only be declared on a type}}{{10-17=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
override class let gli4: Int = 0 // expected-error {{class properties may only be declared on a type}}{{10-16=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{1-10=}}
static override let gli5: Int = 0 // expected-error {{static properties may only be declared on a type}}{{1-8=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{8-17=}}
class override let gli6: Int = 0 // expected-error {{class properties may only be declared on a type}}{{1-7=}}
// expected-error@-1 {{'override' can only be specified on class members}}{{7-16=}}
func inGlobalFunc() {
static var v1: Int // expected-error {{static properties may only be declared on a type}}{{3-10=}}
class var v2: Int // expected-error {{class properties may only be declared on a type}}{{3-9=}}
static let l1: Int = 0 // expected-error {{static properties may only be declared on a type}}{{3-10=}}
class let l2: Int = 0 // expected-error {{class properties may only be declared on a type}}{{3-9=}}
v1 = 1; v2 = 1
_ = v1+v2+l1+l2
}
struct InMemberFunc {
func member() {
static var v1: Int // expected-error {{static properties may only be declared on a type}}{{5-12=}}
class var v2: Int // expected-error {{class properties may only be declared on a type}}{{5-11=}}
static let l1: Int = 0 // expected-error {{static properties may only be declared on a type}}{{5-12=}}
class let l2: Int = 0 // expected-error {{class properties may only be declared on a type}}{{5-11=}}
v1 = 1; v2 = 1
_ = v1+v2+l1+l2
}
}
struct S { // expected-note 3{{extended type declared here}}
static var v1: Int = 0
class var v2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static var v3: Int { return 0 }
class var v4: Int { return 0 } // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static final var v5 = 1 // expected-error {{only classes and class members may be marked with 'final'}}
static let l1: Int = 0
class let l2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static final let l3 = 1 // expected-error {{only classes and class members may be marked with 'final'}}
}
extension S {
static var ev1: Int = 0
class var ev2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static var ev3: Int { return 0 }
class var ev4: Int { return 0 } // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static let el1: Int = 0
class let el2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
}
enum E { // expected-note 3{{extended type declared here}}
static var v1: Int = 0
class var v2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static var v3: Int { return 0 }
class var v4: Int { return 0 } // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static final var v5 = 1 // expected-error {{only classes and class members may be marked with 'final'}}
static let l1: Int = 0
class let l2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static final let l3 = 1 // expected-error {{only classes and class members may be marked with 'final'}}
}
extension E {
static var ev1: Int = 0
class var ev2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static var ev3: Int { return 0 }
class var ev4: Int { return 0 } // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
static let el1: Int = 0
class let el2: Int = 0 // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
}
class C {
static var v1: Int = 0
class final var v3: Int = 0 // expected-error {{class stored properties not supported}}
class var v4: Int = 0 // expected-error {{class stored properties not supported}}
static var v5: Int { return 0 }
class var v6: Int { return 0 }
static final var v7: Int = 0 // expected-error {{static declarations are already final}} {{10-16=}}
static let l1: Int = 0
class let l2: Int = 0 // expected-error {{class stored properties not supported in classes; did you mean 'static'?}}
class final let l3: Int = 0 // expected-error {{class stored properties not supported}}
static final let l4 = 2 // expected-error {{static declarations are already final}} {{10-16=}}
}
extension C {
static var ev1: Int = 0
class final var ev2: Int = 0 // expected-error {{class stored properties not supported}}
class var ev3: Int = 0 // expected-error {{class stored properties not supported}}
static var ev4: Int { return 0 }
class var ev5: Int { return 0 }
static final var ev6: Int = 0 // expected-error {{static declarations are already final}} {{10-16=}}
static let el1: Int = 0
class let el2: Int = 0 // expected-error {{class stored properties not supported in classes; did you mean 'static'?}}
class final let el3: Int = 0 // expected-error {{class stored properties not supported in classes; did you mean 'static'?}}
static final let el4: Int = 0 // expected-error {{static declarations are already final}} {{10-16=}}
}
protocol P { // expected-note{{extended type declared here}}
// Both `static` and `class` property requirements are equivalent in protocols rdar://problem/17198298
static var v1: Int { get }
class var v2: Int { get } // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}}
static final var v3: Int { get } // expected-error {{only classes and class members may be marked with 'final'}}
static let l1: Int // expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
class let l2: Int // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}} expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
}
extension P {
class var v4: Int { return 0 } // expected-error {{class properties are only allowed within classes; use 'static' to declare a static property}} {{3-8=static}}
}
struct S1 {
// rdar://15626843
static var x: Int // expected-error {{'static var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{17-17= = <#initializer#>}}
var y = 1
static var z = 5
}
extension S1 {
static var zz = 42
static var xy: Int { return 5 }
}
enum E1 {
static var y: Int {
get {}
}
}
class C1 {
class var x: Int // expected-error {{class stored properties not supported}} expected-error {{'class var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{16-16= = <#initializer#>}}
class let x: Int // expected-error {{class stored properties not supported}} expected-error {{'class let' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{16-16= = <#initializer#>}}
static var x: Int // expected-error {{'static var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{17-17= = <#initializer#>}}
static let x: Int // expected-error {{'static let' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{17-17= = <#initializer#>}}
// FIXME: We immediately invalidate the pattern binding after the first error
// is emitted, but we could definitely emit a second round of fixits for the
// other pattern here.
static var (x, y): (Int, Int), (z, w): (Int, Int) // expected-error {{'static var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1 {{add an initializer to silence this error}} {{31-31= = <#initializer#>}}
}
class C2 {
var x: Int = 19
class var x: Int = 17 // expected-error{{class stored properties not supported}}
func xx() -> Int { return self.x + C2.x }
}
class ClassHasVars {
static var computedStatic: Int { return 0 } // expected-note 3{{overridden declaration is here}}
final class var computedFinalClass: Int { return 0 } // expected-note 3{{overridden declaration is here}}
class var computedClass: Int { return 0 }
var computedInstance: Int { return 0 }
}
class ClassOverridesVars : ClassHasVars {
override static var computedStatic: Int { return 1 } // expected-error {{cannot override static property}}
override static var computedFinalClass: Int { return 1 } // expected-error {{static property overrides a 'final' class property}}
override class var computedClass: Int { return 1 }
override var computedInstance: Int { return 1 }
}
class ClassOverridesVars2 : ClassHasVars {
override final class var computedStatic: Int { return 1 } // expected-error {{cannot override static property}}
override final class var computedFinalClass: Int { return 1 } // expected-error {{class property overrides a 'final' class property}}
}
class ClassOverridesVars3 : ClassHasVars {
override class var computedStatic: Int { return 1 } // expected-error {{cannot override static property}}
override class var computedFinalClass: Int { return 1 } // expected-error {{class property overrides a 'final' class property}}
}
struct S2 {
var x: Int = 19
static var x: Int = 17
func xx() -> Int { return self.x + C2.x }
}
// Mutating vs non-mutating conflict with static stored property witness - rdar://problem/19887250
protocol Proto {
static var name: String {get set}
}
struct ProtoAdopter : Proto {
static var name: String = "name" // no error, even though static setters aren't mutating
}
// Make sure the logic remains correct if we synthesized accessors for our stored property
protocol ProtosEvilTwin {
static var name: String {get set}
}
extension ProtoAdopter : ProtosEvilTwin {}
// rdar://18990358
public struct Foo { // expected-note {{to match this opening '{'}}}
public static let S { _ = 0; aaaaaa // expected-error{{computed property must have an explicit type}} {{22-22=: <# Type #>}}
// expected-error@-1{{type annotation missing in pattern}}
// expected-error@-2{{'let' declarations cannot be computed properties}} {{17-20=var}}
// expected-error@-3{{cannot find 'aaaaaa' in scope}}
}
// expected-error@+1 {{expected '}' in struct}}
|