Files
swift-mirror/test/expr/primary/super/closures.swift
Anthony Latsis 7f2b236710 [NFC] test: Move super in closure tests out of test/Parse
This is diagnosed during semantic pre-checking, not parsing.
2024-04-18 23:07:14 +03:00

46 lines
1.5 KiB
Swift

// RUN: %target-typecheck-verify-swift
class Base {
var foo: Int
init() {}
}
class Derived : Base {
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()
}
}