mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When type-checking a return statement's result, pass a new ContextualTypePurpose when that return statement appears in a function with a single expression. When solving the corresponding constraint system, the conversion constraint will have a new ConstraintKind. When matching types, check whether the constraint kind is this new kind, meaning that the constraint is between a function's single expression and the function's result. If it is, allow a conversion from an uninhabited type (the expression's type) to anything (the function's result type) by adding an uninhabited upcast restriction to the vector of conversions. Finally, at coercion time, upon encountering this restriction, call coerceUninhabited, replacing the original expression with an UninhabitedUpcastExpr. Finally, at SILGen time, treat this UninhabitedUpcastExpr as a ForcedCheckedCastExpr. Eliminates the bare ConstraintSystem usage from typeCheckFunctionBodyUntil, ensuring that the same code path is followed for all function bodies.
261 KiB
261 KiB