File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,29 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
278
278
status |= type;
279
279
param.Type = type.getPtrOrNull ();
280
280
281
+ if (param.SpecifierKind == ParsedParameter::InOut) {
282
+ if (auto *fnTR = dyn_cast_or_null<FunctionTypeRepr>(param.Type )) {
283
+ // If the input to the function isn't parenthesized, apply the inout
284
+ // to the first (only) parameter, as we would in Swift 2. (This
285
+ // syntax is deprecated in Swift 3.)
286
+ TypeRepr *argsTR = fnTR->getArgsTypeRepr ();
287
+ if (!isa<TupleTypeRepr>(argsTR)) {
288
+ auto *newArgsTR =
289
+ new (Context) InOutTypeRepr (argsTR, param.LetVarInOutLoc );
290
+ auto *newTR =
291
+ new (Context) FunctionTypeRepr (fnTR->getGenericParams (),
292
+ newArgsTR,
293
+ fnTR->getThrowsLoc (),
294
+ fnTR->getArrowLoc (),
295
+ fnTR->getResultTypeRepr ());
296
+ newTR->setGenericSignature (fnTR->getGenericSignature ());
297
+ param.Type = newTR;
298
+ param.SpecifierKind = ParsedParameter::Let;
299
+ param.LetVarInOutLoc = SourceLoc ();
300
+ }
301
+ }
302
+ }
303
+
281
304
// If we didn't parse a type, then we already diagnosed that the type
282
305
// was invalid. Remember that.
283
306
if (type.isParseError () && !type.hasCodeCompletion ())
Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ class r21949448 {
158
158
159
159
// SE-0066 - Standardize function type argument syntax to require parentheses
160
160
let _ : Int -> Float // expected-error {{single argument function types require parentheses}} {{9-9=(}} {{12-12=)}}
161
+ let _ : inout Int -> Float // expected-error {{single argument function types require parentheses}} {{9-9=(}} {{18-18=)}}
162
+ func testNoParenFunction( x: Int -> Float ) { } // expected-error {{single argument function types require parentheses}} {{29-29=(}} {{32-32=)}}
163
+ func testNoParenFunction( x: inout Int -> Float ) { } // expected-error {{single argument function types require parentheses}} {{29-29=(}} {{38-38=)}}
161
164
162
165
func foo1( a : UnsafePointer < Void > ) { } // expected-warning {{UnsafePointer<Void> has been replaced by UnsafeRawPointer}}{{15-34=UnsafeRawPointer}}
163
166
func foo2( a : UnsafeMutablePointer < ( ) > ) { } // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}{{15-39=UnsafeMutableRawPointer}}
You can’t perform that action at this time.
0 commit comments