Repository: apple/swift
File: test/Sema/lifetime_attr.swift (Swift)

Code before:
  _ = \Test.v1 // expected-error {{key path cannot refer to nonescapable type 'Test'}}
  _ = \Test.v2 // expected-error {{key path cannot refer to nonescapable type 'Test'}} expected-error {{key path cannot refer to nonescapable type 'NE'}}

  func use(t: Test) {
    t[keyPath: \.v1] // expected-error {{key path cannot refer to nonescapable type 'Test'}}
    t[keyPath: \.v2] // expected-error {{key path cannot refer to nonescapable type 'Test'}} expected-error {{key path cannot refer to nonescapable type 'NE'}}
  }
}

// rdar://146401190 ([nonescapable] implement non-inout parameter dependencies)
@_lifetime(span: borrow holder)
func testParameterDep(holder: AnyObject, span: Span<Int>) {}  // expected-error{{lifetime-dependent parameter 'span' must be 'inout'}}

@_lifetime(&ne)
func inoutLifetimeDependence(_ ne: inout NE) -> NE {
  ne
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
// expected-note@-1{{use '@_lifetime(&k)' instead}}
func dependOnEscapable(_ k: inout Klass) -> NE {
  NE()
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
// expected-note@-1{{use '@_lifetime(borrow k)' instead}}
func dependOnEscapable(_ k: borrowing Klass) -> NE { 
  NE()
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
                   // expected-note@-1{{use '@_lifetime(borrow k)' instead}}
func dependOnEscapable(_ k: consuming Klass) -> NE { 
  NE()
}

struct Wrapper : ~Escapable {
  var _ne: NE

  var ne: NE {
    @_lifetime(copy self)
    get {
      _ne
    }
    @_lifetime(self: &self)
    nonmutating _modify {// expected-error{{lifetime-dependent parameter 'self' must be 'inout'}}
      // expected-error@-1{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
    }
  }

  var otherNE: NE {

Review comment (suggestion):
```suggestion
@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
                   // expected-note@-1{{use '@_lifetime(borrow k)' instead}}
```

Code after:
  _ = \Test.v1 // expected-error {{key path cannot refer to nonescapable type 'Test'}}
  _ = \Test.v2 // expected-error {{key path cannot refer to nonescapable type 'Test'}} expected-error {{key path cannot refer to nonescapable type 'NE'}}

  func use(t: Test) {
    t[keyPath: \.v1] // expected-error {{key path cannot refer to nonescapable type 'Test'}}
    t[keyPath: \.v2] // expected-error {{key path cannot refer to nonescapable type 'Test'}} expected-error {{key path cannot refer to nonescapable type 'NE'}}
  }
}

// rdar://146401190 ([nonescapable] implement non-inout parameter dependencies)
@_lifetime(span: borrow holder)
func testParameterDep(holder: AnyObject, span: Span<Int>) {}  // expected-error{{lifetime-dependent parameter 'span' must be 'inout'}}

@_lifetime(&ne)
func inoutLifetimeDependence(_ ne: inout NE) -> NE {
  ne
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
                   // expected-note@-1{{use '@_lifetime(&k)' instead}}
func dependOnEscapable(_ k: inout Klass) -> NE {
  NE()
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
                   // expected-note@-1{{use '@_lifetime(borrow k)' instead}}
func dependOnEscapable(_ k: borrowing Klass) -> NE { 
  NE()
}

@_lifetime(copy k) // expected-error{{cannot copy the lifetime of an Escapable type}}
                   // expected-note@-1{{use '@_lifetime(borrow k)' instead}}
func dependOnEscapable(_ k: consuming Klass) -> NE { 
  NE()
}

struct Wrapper : ~Escapable {
  var _ne: NE

  var ne: NE {
    @_lifetime(copy self)
    get {
      _ne
    }
    @_lifetime(self: &self)
    nonmutating _modify {// expected-error{{lifetime-dependent parameter 'self' must be 'inout'}}
      // expected-error@-1{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
    }
  }

  var otherNE: NE {