Files
swift-mirror/test/SourceKit/CodeComplete/complete_with_closure_param.swift
Slava Pestov 79a1512576 Sema: Three fixes for the new @escaping attribute
- If a parameter type is a sugared function type, mark the type
  as non-escaping by default. Previously, we were only doing this
  if the parameter type was written as a function type, with no
  additional sugar.

  This means in the following cases, the function parameter type
  is now non-escaping:

  func foo(f: ((Int) -> Void))

  typealias Fn = (Int) -> Void
  func foo(f: Fn)

- Also, allow @escaping to be used in the above cases:

  func foo(f: @escaping ((Int) -> Void))

  typealias Fn = (Int) -> Void
  func foo(f: @escaping Fn)

- Diagnose usages of @escaping in inappropriate locations, instead
  of just ignoring them.

It is unfortunate that sometimes we end up desugaring the typealias,
but currently there are other cases where this occurs too, such as
qualified lookpu of protocol typealiases with a concrete base
type, and generic type aliases. A more general representation for
sugared types (such as an AttributedType sugared type) would allow
us to solve this in a more satisfactory manner in the future.

However at the very least this patch factors out the common code
paths and adds comments, so it shouldn't be too bad going forward.

Note that this is a source-breaking change, both because @escaping
might need to be added to parameters with a sugared function type,
and @escaping might be removed if it appears somewhere where we
do not mark function types as non-escaping by default.
2016-08-17 19:37:23 -07:00

21 lines
704 B
Swift

typealias MyFnTy = Int -> Int
class C {
func foo(_ x: Int ->Int) {}
func foo2(_ x: MyFnTy) {}
}
C().
// RUN: %sourcekitd-test -req=complete -pos=7:5 %s -- %s | %FileCheck %s
// CHECK: key.kind: source.lang.swift.decl.function.method.instance,
// CHECK-NEXT: key.name: "foo(:)",
// CHECK-NEXT: key.sourcetext: "foo(<#T##x: (Int) -> Int##(Int) -> Int#>)",
// CHECK-NEXT: key.description: "foo(x: (Int) -> Int)",
// CHECK-NEXT: key.typename: "Void",
// CHECK: key.kind: source.lang.swift.decl.function.method.instance,
// CHECK-NEXT: key.name: "foo2(:)",
// CHECK-NEXT: key.sourcetext: "foo2(<#T##x: (Int) -> Int##(Int) -> Int#>)",
// CHECK-NEXT: key.description: "foo2(x: (Int) -> Int)",