In Swift 3 mode, allow "tuple unsplatting" in certain cases. (#7077)

Swift 3.0 allowed constructing an enum or calling a function-typed
property with multiple arguments even when a single argument of tuple
type was expected. Emulate that in Swift 3 mode by wrapping in an
extra level of parentheses when the situation comes up.

Last vestiges of fallout from SE-0110. Hopefully last, anyway. A nice
follow-up to this commit might be to /warn/ in Swift 3 mode when this
happens.

rdar://problem/30171399
This commit is contained in:
Jordan Rose
2017-01-27 11:19:07 -08:00
committed by GitHub
parent 1cf1961fc7
commit 7c8117301a
5 changed files with 244 additions and 9 deletions

View File

@@ -653,6 +653,21 @@ matchCallArguments(ConstraintSystem &cs, ConstraintKind kind,
getCalleeDeclAndArgs(cs, locator, argLabelsScratch);
auto params = decomposeParamType(paramType, callee, calleeLevel);
if (callee && cs.getASTContext().isSwiftVersion3()
&& argType->is<TupleType>()) {
// Hack: In Swift 3 mode, accept `foo(x, y)` for `foo((x, y))` when the
// callee is a function-typed property or an enum constructor whose
// argument is a single unlabeled type parameter.
if (auto *prop = dyn_cast<VarDecl>(callee)) {
auto *fnType = prop->getInterfaceType()->getAs<AnyFunctionType>();
if (fnType && fnType->getInput()->isTypeParameter())
argType = ParenType::get(cs.getASTContext(), argType);
} else if (auto *enumCtor = dyn_cast<EnumElementDecl>(callee)) {
if (enumCtor->getArgumentInterfaceType()->isTypeParameter())
argType = ParenType::get(cs.getASTContext(), argType);
}
}
// Extract the arguments.
auto args = decomposeArgType(argType, argLabels);