mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Parse] Attach 'inout' to Swift 2 unparenthesized function params. (#4241)
This syntax is no longer permitted, but we need to parse it like Swift 2 did in order to produce the fix-it that matches Swift 2 behavior. rdar://problem/26681485
This commit is contained in:
@@ -278,6 +278,29 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
|||||||
status |= type;
|
status |= type;
|
||||||
param.Type = type.getPtrOrNull();
|
param.Type = type.getPtrOrNull();
|
||||||
|
|
||||||
|
if (param.SpecifierKind == ParsedParameter::InOut) {
|
||||||
|
if (auto *fnTR = dyn_cast_or_null<FunctionTypeRepr>(param.Type)) {
|
||||||
|
// If the input to the function isn't parenthesized, apply the inout
|
||||||
|
// to the first (only) parameter, as we would in Swift 2. (This
|
||||||
|
// syntax is deprecated in Swift 3.)
|
||||||
|
TypeRepr *argsTR = fnTR->getArgsTypeRepr();
|
||||||
|
if (!isa<TupleTypeRepr>(argsTR)) {
|
||||||
|
auto *newArgsTR =
|
||||||
|
new (Context) InOutTypeRepr(argsTR, param.LetVarInOutLoc);
|
||||||
|
auto *newTR =
|
||||||
|
new (Context) FunctionTypeRepr(fnTR->getGenericParams(),
|
||||||
|
newArgsTR,
|
||||||
|
fnTR->getThrowsLoc(),
|
||||||
|
fnTR->getArrowLoc(),
|
||||||
|
fnTR->getResultTypeRepr());
|
||||||
|
newTR->setGenericSignature(fnTR->getGenericSignature());
|
||||||
|
param.Type = newTR;
|
||||||
|
param.SpecifierKind = ParsedParameter::Let;
|
||||||
|
param.LetVarInOutLoc = SourceLoc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we didn't parse a type, then we already diagnosed that the type
|
// If we didn't parse a type, then we already diagnosed that the type
|
||||||
// was invalid. Remember that.
|
// was invalid. Remember that.
|
||||||
if (type.isParseError() && !type.hasCodeCompletion())
|
if (type.isParseError() && !type.hasCodeCompletion())
|
||||||
|
|||||||
@@ -158,6 +158,9 @@ class r21949448 {
|
|||||||
|
|
||||||
// SE-0066 - Standardize function type argument syntax to require parentheses
|
// SE-0066 - Standardize function type argument syntax to require parentheses
|
||||||
let _ : Int -> Float // expected-error {{single argument function types require parentheses}} {{9-9=(}} {{12-12=)}}
|
let _ : Int -> Float // expected-error {{single argument function types require parentheses}} {{9-9=(}} {{12-12=)}}
|
||||||
|
let _ : inout Int -> Float // expected-error {{single argument function types require parentheses}} {{9-9=(}} {{18-18=)}}
|
||||||
|
func testNoParenFunction(x: Int -> Float) {} // expected-error {{single argument function types require parentheses}} {{29-29=(}} {{32-32=)}}
|
||||||
|
func testNoParenFunction(x: inout Int -> Float) {} // expected-error {{single argument function types require parentheses}} {{29-29=(}} {{38-38=)}}
|
||||||
|
|
||||||
func foo1(a : UnsafePointer<Void>) {} // expected-warning {{UnsafePointer<Void> has been replaced by UnsafeRawPointer}}{{15-34=UnsafeRawPointer}}
|
func foo1(a : UnsafePointer<Void>) {} // expected-warning {{UnsafePointer<Void> has been replaced by UnsafeRawPointer}}{{15-34=UnsafeRawPointer}}
|
||||||
func foo2(a : UnsafeMutablePointer<()>) {} // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}{{15-39=UnsafeMutableRawPointer}}
|
func foo2(a : UnsafeMutablePointer<()>) {} // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}{{15-39=UnsafeMutableRawPointer}}
|
||||||
|
|||||||
Reference in New Issue
Block a user