mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
- 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.
27 lines
1.8 KiB
Swift
27 lines
1.8 KiB
Swift
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=COMPLETE | %FileCheck %s
|
|
|
|
typealias FunctionTypealias = (Int, Int) -> Bool
|
|
typealias OptionalFunctionTypealias = ((Int, Int) -> Bool)?
|
|
|
|
struct FooStruct {
|
|
func instanceMethod1(_ callback: (Int, Int) -> Void) {}
|
|
func instanceMethod2(_ callback: ((Int, Int) -> Void)?) {}
|
|
func instanceMethod3(_ callback: ((Int, Int) -> Void)??) {}
|
|
func instanceMethod4(_ callback: ((Int, Int) -> Void)!) {}
|
|
func instanceMethod5(_ callback: FunctionTypealias) {}
|
|
func instanceMethod6(_ callback: FunctionTypealias?) {}
|
|
func instanceMethod7(_ callback: OptionalFunctionTypealias) {}
|
|
}
|
|
|
|
FooStruct().#^COMPLETE^#
|
|
|
|
// CHECK: Begin completions, 7 items
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod1({#(callback): (Int, Int) -> Void##(Int, Int) -> Void#})[#Void#]; name=instanceMethod1(callback: (Int, Int) -> Void){{$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod2({#(callback): ((Int, Int) -> Void)?##(Int, Int) -> Void#})[#Void#]{{; name=.+$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod3({#(callback): ((Int, Int) -> Void)??##(Int, Int) -> Void#})[#Void#]{{; name=.+$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod4({#(callback): ((Int, Int) -> Void)!##(Int, Int) -> Void#})[#Void#]{{; name=.+$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod5({#(callback): (Int, Int) -> Bool##(Int, Int) -> Bool#})[#Void#]{{; name=.+$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod6({#(callback): FunctionTypealias?##(Int, Int) -> Bool#})[#Void#]{{; name=.+$}}
|
|
// CHECK-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod7({#(callback): OptionalFunctionTypealias##(Int, Int) -> Bool#})[#Void#]{{; name=.+$}}
|
|
// CHECK: End completions
|