[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:
Jordan Rose
2016-08-11 16:42:06 -07:00
committed by GitHub
parent b3eee4c5a7
commit 294bbd8e17
2 changed files with 26 additions and 0 deletions

View File

@@ -278,6 +278,29 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
status |= type;
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
// was invalid. Remember that.
if (type.isParseError() && !type.hasCodeCompletion())