Files
swift-mirror/test/attr/attr_implicitselfcapture.swift
Doug Gregor abfc9bcdc4 Add @_implicitSelfCapture attribute to disable "self." requirement.
Add a new parameter attribute `@_implicitSelfCapture` that disables the
requirement to explicitly use `self.` to refer to a member of `self`
in an escaping closure.

Part of rdar://76927008.
2021-04-20 17:26:07 -07:00

25 lines
833 B
Swift

// RUN: %target-typecheck-verify-swift
func takeFn(@_implicitSelfCapture fn: @escaping () -> Int) { }
func takeEscapingFn(fn: @escaping () -> Int) { }
class C {
var property: Int = 0
func method() { }
func testMethod() {
takeFn { // no errors
method()
return property
}
takeEscapingFn { // expected-note 2 {{capture 'self' explicitly to enable implicit 'self' in this closure}}
method() // expected-error{{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
// expected-note@-1{{reference 'self.' explicitly}}
return property // expected-error{{reference to property 'property' in closure requires explicit use of 'self' to make capture semantics explicit}}
// expected-note@-1{{reference 'self.' explicitly}}
}
}
}