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