These changes implement some oft-requested tweaks and fixes to our closure implementation:

- Closures that are comprised of only a single return statement are now considered to be "single expression" closures. (rdar://problem/17550847)
- Unannotated single expression closures with non-void return types can now be used in void contexts. (rdar://problem/17228969)
- Situations where a multi-statement closure's type could not be inferred because of the lack of a return-type annotation are now properly diagnosed. (rdar://problem/17212107)

I also encountered a number of crashers along the way, which should now be fixed.

Swift SVN r24817
This commit is contained in:
Joe Pamer
2015-01-29 18:48:39 +00:00
parent f02ba53d97
commit 6a70bd085e
10 changed files with 183 additions and 28 deletions

View File

@@ -1961,6 +1961,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
ConversionRestrictionKind::ForceUnchecked);
}
}
// If the types disagree, but we're comparing a non-void, single-expression
// closure result type to a void function result type, allow the conversion.
{
if (concrete && kind >= TypeMatchKind::Subtype && type2->isVoid()) {
SmallVector<LocatorPathElt, 2> parts;
locator.getLocatorParts(parts);
while (!parts.empty()) {
if (parts.back().getKind() == ConstraintLocator::ClosureResult) {
return SolutionKind::Solved;
}
parts.pop_back();
}
}
}
commit_to_conversions:
// When we hit this point, we're committed to the set of potential