mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user