mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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;
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user