Files
swift-mirror/test/Parse/super.swift
Jordan Rose fac5a83bbf Allow capturing super in explicit closures and nested functions.
The previous commit enabled this; now it's just about removing the
restriction in the parser and tightening up code completion.

Using 'super' in a closure where 'self' is captured weak or unowned still
doesn't work; the reference to 'self' within the closure is treated as
strong regardless of how it's declared. Fixing this requires a cascade of
effort, so instead I just cloned rdar://problem/19755221.

rdar://problem/14883824

Swift SVN r25065
2015-02-07 03:56:11 +00:00

82 lines
2.7 KiB
Swift

// RUN: %target-parse-verify-swift
class B {
var foo: Int
func bar() {}
init() {}
init(x: Int) {}
subscript(x: Int) -> Int {
get {}
set {}
}
}
class D : B {
override init() {
super.init()
}
override init(x:Int) {
super.init // expected-error {{'super.init' cannot be referenced without arguments}} expected-error {{could not find an overload for 'init' that accepts the supplied arguments}}
}
func super_calls() {
super.foo // expected-error {{expression resolves to an unused l-value}}
super.foo.bar // expected-error {{'Int' does not have a member named 'bar'}}
super.bar // expected-error {{expression resolves to an unused function}}
super.bar()
super.init // expected-error{{'super.init' cannot be called outside of an initializer}}
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
super.init(0) // expected-error{{'super.init' cannot be called outside of an initializer}}
super[0] // expected-error {{expression resolves to an unused l-value}}
}
func bad_super_1() {
super.$0 // expected-error{{expected identifier or 'init'}}
}
func bad_super_2() {
super(0) // expected-error{{expected '.' or '[' after 'super'}}
}
}
class Closures : B {
func captureWeak() {
let g = { [weak self] () -> Void in // expected-note + {{'self' explicitly captured here}}
super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
}
g()
}
func captureUnowned() {
let g = { [unowned self] () -> Void in // expected-note + {{'self' explicitly captured here}}
super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
}
g()
}
func nestedInner() {
let g = { () -> Void in
let h = { [weak self] () -> Void in // expected-note + {{'self' explicitly captured here}}
super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
nil ?? super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
}
h()
}
g()
}
func nestedOuter() {
let g = { [weak self] () -> Void in // expected-note + {{'self' explicitly captured here}}
let h = { () -> Void in
super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
nil ?? super.foo() // expected-error {{using 'super' in a closure where 'self' is explicitly captured is not yet supported}}
}
h()
}
g()
}
}