11// RUN: %target-typecheck-verify-swift
22
33struct SimpleCallable {
4- func call ( _ x: Float ) -> Float {
4+ func callFunction ( _ x: Float ) -> Float {
55 return x
66 }
77}
@@ -21,11 +21,11 @@ let _: (Float) -> Float = foo
2121
2222// Test direct `call` member references.
2323
24- _ = foo. call ( 1 )
25- _ = [ 1 , 2 , 3 ] . map ( foo. call )
26- _ = foo. call ( foo ( 1 ) )
27- _ = foo ( foo. call ( 1 ) )
28- let _: ( Float ) -> Float = foo. call
24+ _ = foo. callFunction ( 1 )
25+ _ = [ 1 , 2 , 3 ] . map ( foo. callFunction )
26+ _ = foo. callFunction ( foo ( 1 ) )
27+ _ = foo ( foo. callFunction ( 1 ) )
28+ let _: ( Float ) -> Float = foo. callFunction
2929
3030func callable( ) -> SimpleCallable {
3131 return SimpleCallable ( )
@@ -42,43 +42,56 @@ extension SimpleCallable {
4242_ = foo. foo ( 1 )
4343_ = foo. bar ( ) ( 1 )
4444_ = callable ( ) ( 1 )
45- _ = [ 1 , 2 , 3 ] . map ( foo. foo. call )
46- _ = [ 1 , 2 , 3 ] . map ( foo. bar ( ) . call )
47- _ = [ 1 , 2 , 3 ] . map ( callable ( ) . call )
45+ _ = [ 1 , 2 , 3 ] . map ( foo. foo. callFunction )
46+ _ = [ 1 , 2 , 3 ] . map ( foo. bar ( ) . callFunction )
47+ _ = [ 1 , 2 , 3 ] . map ( callable ( ) . callFunction )
4848
4949struct MultipleArgsCallable {
50- func call ( x: Int , y: Float ) -> [ Int ] {
50+ func callFunction ( x: Int , y: Float ) -> [ Int ] {
5151 return [ x]
5252 }
5353}
5454
5555let bar = MultipleArgsCallable ( )
5656_ = bar ( x: 1 , y: 1 )
57- _ = bar. call ( x: 1 , y: 1 )
58- _ = bar ( x: bar. call ( x: 1 , y: 1 ) [ 0 ] , y: 1 )
59- _ = bar. call ( x: bar ( x: 1 , y: 1 ) [ 0 ] , y: 1 )
57+ _ = bar. callFunction ( x: 1 , y: 1 )
58+ _ = bar ( x: bar. callFunction ( x: 1 , y: 1 ) [ 0 ] , y: 1 )
59+ _ = bar. callFunction ( x: bar ( x: 1 , y: 1 ) [ 0 ] , y: 1 )
6060_ = bar ( 1 , 1 ) // expected-error {{missing argument labels 'x:y:' in call}}
6161
6262struct Extended { }
6363extension Extended {
6464 @discardableResult
65- func call ( ) -> Extended {
65+ func callFunction ( ) -> Extended {
6666 return self
6767 }
6868}
6969var extended = Extended ( )
70- extended ( ) ( ) . call ( ) ( )
70+ extended ( ) ( ) . callFunction ( ) ( )
71+
72+ struct TakesTrailingClosure {
73+ func callFunction( _ fn: ( ) -> Void ) {
74+ fn ( )
75+ }
76+ func callFunction( _ x: Int , label y: Float , _ fn: ( Int , Float ) -> Void ) {
77+ fn ( x, y)
78+ }
79+ }
80+ var takesTrailingClosure = TakesTrailingClosure ( )
81+ takesTrailingClosure { print ( " Hi " ) }
82+ takesTrailingClosure ( ) { print ( " Hi " ) }
83+ takesTrailingClosure ( 1 , label: 2 ) { _ = Float ( $0) + $1 }
7184
7285struct OptionalCallable {
73- func call ( ) -> OptionalCallable ? {
86+ func callFunction ( ) -> OptionalCallable ? {
7487 return self
7588 }
7689}
7790var optional = OptionalCallable ( )
78- _ = optional ( ) ? . call ( ) ? ( )
91+ _ = optional ( ) ? . callFunction ( ) ? ( )
7992
8093struct Variadic {
81- func call ( _ args: Int ... ) -> [ Int ] {
94+ func callFunction ( _ args: Int ... ) -> [ Int ] {
8295 return args
8396 }
8497}
@@ -88,35 +101,35 @@ _ = variadic(1, 2, 3)
88101
89102struct Mutating {
90103 var x : Int
91- mutating func call ( ) {
104+ mutating func callFunction ( ) {
92105 x += 1
93106 }
94107}
95108func testMutating( _ x: Mutating , _ y: inout Mutating ) {
96109 _ = x ( ) // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}}
97- _ = x. call ( ) // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}}
110+ _ = x. callFunction ( ) // expected-error {{cannot use mutating member on immutable value: 'x' is a 'let' constant}}
98111 _ = y ( )
99- _ = y. call ( )
112+ _ = y. callFunction ( )
100113}
101114
102115struct Inout {
103- func call ( _ x: inout Int ) {
116+ func callFunction ( _ x: inout Int ) {
104117 x += 5
105118 }
106119}
107120func testInout( _ x: Inout , _ arg: inout Int ) {
108121 x ( & arg)
109- x. call ( & arg)
122+ x. callFunction ( & arg)
110123 // TODO: Improve this error to match the error using a direct `call` member reference.
111124 // expected-error @+2 {{cannot invoke 'x' with an argument list of type '(Int)'}}
112125 // expected-error @+1 {{cannot call value of non-function type 'Inout'}}
113126 x ( arg)
114127 // expected-error @+1 {{passing value of type 'Int' to an inout parameter requires explicit '&'}}
115- x. call ( arg)
128+ x. callFunction ( arg)
116129}
117130
118131struct Autoclosure {
119- func call ( _ condition: @autoclosure ( ) -> Bool ,
132+ func callFunction ( _ condition: @autoclosure ( ) -> Bool ,
120133 _ message: @autoclosure ( ) -> String ) {
121134 if condition ( ) {
122135 print ( message ( ) )
@@ -129,10 +142,10 @@ func testAutoclosure(_ x: Autoclosure) {
129142}
130143
131144struct Throwing {
132- func call ( ) throws -> Throwing {
145+ func callFunction ( ) throws -> Throwing {
133146 return self
134147 }
135- func call ( _ f: ( ) throws -> ( ) ) rethrows {
148+ func callFunction ( _ f: ( ) throws -> ( ) ) rethrows {
136149 try f ( )
137150 }
138151}
@@ -145,7 +158,7 @@ enum BinaryOperation {
145158 case add, subtract, multiply, divide
146159}
147160extension BinaryOperation {
148- func call ( _ lhs: Float , _ rhs: Float ) -> Float {
161+ func callFunction ( _ lhs: Float , _ rhs: Float ) -> Float {
149162 switch self {
150163 case . add: return lhs + rhs
151164 case . subtract: return lhs - rhs
@@ -157,12 +170,12 @@ extension BinaryOperation {
157170_ = BinaryOperation . add ( 1 , 2 )
158171
159172class BaseClass {
160- func call ( ) -> Self {
173+ func callFunction ( ) -> Self {
161174 return self
162175 }
163176}
164177class SubClass : BaseClass {
165- override func call ( ) -> Self {
178+ override func callFunction ( ) -> Self {
166179 return self
167180 }
168181}
@@ -173,10 +186,10 @@ func testIUO(a: SimpleCallable!, b: MultipleArgsCallable!, c: Extended!,
173186 _ = a ( 1 )
174187 _ = b ( x: 1 , y: 1 )
175188 _ = c ( )
176- _ = d ( ) ? . call ( ) ? ( )
189+ _ = d ( ) ? . callFunction ( ) ? ( )
177190 _ = e ( )
178191 _ = e ( 1 , 2 , 3 )
179- // FIXME(TF-444): `mutating func call ` and IUO doesn't work.
192+ // FIXME(TF-444): `mutating func callFunction ` and IUO doesn't work.
180193 // _ = f()
181194 _ = g ( & inoutInt)
182195 _ = try ? h ( )
0 commit comments