Skip to content

Commit 6352764

Browse files
Merge pull request swiftlang#24271 from nate-chandler/nate/49581931-opaque-implicit-return-constraint
Create opaque type constraint for single expr return. [49581931]
2 parents fb8bd3a + bf42fbd commit 6352764

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,8 @@ ConstraintSystem::solveImpl(Expr *&expr,
11561156
if (convertType) {
11571157
auto constraintKind = ConstraintKind::Conversion;
11581158

1159-
if (getContextualTypePurpose() == CTP_ReturnStmt
1159+
if ((getContextualTypePurpose() == CTP_ReturnStmt ||
1160+
getContextualTypePurpose() == CTP_ReturnSingleExpr)
11601161
&& Options.contains(ConstraintSystemFlags::UnderlyingTypeForOpaqueReturnType))
11611162
constraintKind = ConstraintKind::OpaqueUnderlyingType;
11621163

test/type/opaque.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ func recursion(x: Int) -> some P {
174174
return recursion(x: x - 1)
175175
}
176176

177-
func noReturnStmts() -> some P { fatalError() } // expected-error{{no return statements}}
177+
// FIXME: We need to emit a better diagnostic than the failure to convert Never to opaque.
178+
func noReturnStmts() -> some P { fatalError() } // expected-error{{cannot convert return expression of type 'Never' to return type 'some P'}} expected-error{{no return statements}}
178179

179180
func mismatchedReturnTypes(_ x: Bool, _ y: Int, _ z: String) -> some P { // expected-error{{do not have matching underlying types}}
180181
if x {

0 commit comments

Comments
 (0)