Skip to content

Commit 11877d7

Browse files
[Sema][Revert] Revert CTP to CTP_ReturnStmt for closure result in return stmt
1 parent 7a2e6d8 commit 11877d7

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ class SyntacticElementConstraintGenerator
891891
}
892892

893893
SolutionApplicationTarget target(resultExpr, context.getAsDeclContext(),
894-
CTP_ClosureResult, resultType,
894+
CTP_ReturnStmt, resultType,
895895
/*isDiscarded=*/false);
896896

897897
if (cs.generateConstraints(target, FreeTypeVariableBinding::Disallow)) {
@@ -900,7 +900,7 @@ class SyntacticElementConstraintGenerator
900900
}
901901

902902
cs.setContextualType(target.getAsExpr(), TypeLoc::withoutLoc(resultType),
903-
CTP_ClosureResult);
903+
CTP_ReturnStmt);
904904
cs.setSolutionApplicationTarget(returnStmt, target);
905905
}
906906

@@ -1510,7 +1510,7 @@ class SyntacticElementSolutionApplication
15101510
// number of times.
15111511
{
15121512
SolutionApplicationTarget target(resultExpr, context.getAsDeclContext(),
1513-
CTP_ClosureResult, resultType,
1513+
CTP_ReturnStmt, resultType,
15141514
/*isDiscarded=*/false);
15151515
cs.setSolutionApplicationTarget(returnStmt, target);
15161516

@@ -1576,7 +1576,7 @@ class SyntacticElementSolutionApplication
15761576

15771577
SolutionApplicationTarget resultTarget(
15781578
resultExpr, context.getAsDeclContext(),
1579-
mode == convertToResult ? CTP_ClosureResult : CTP_Unused,
1579+
mode == convertToResult ? CTP_ReturnStmt : CTP_Unused,
15801580
mode == convertToResult ? resultType : Type(),
15811581
/*isDiscarded=*/false);
15821582
if (auto newResultTarget = rewriteTarget(resultTarget))

test/Constraints/callAsFunction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct Test {
8383
var body8: MyLayout {
8484
MyLayout {
8585
let x = ""
86-
return x // expected-error {{cannot convert value of type 'String' to closure result type 'Int'}}
86+
return x // expected-error {{cannot convert return expression of type 'String' to return type 'Int'}}
8787
} content: {
8888
EmptyView()
8989
}

test/decl/circularity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Sub: Base {
4141
var foo = { () -> Int in
4242
let x = 42
4343
// FIXME: Bogus diagnostic
44-
return foo(1) // expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
44+
return foo(1) // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
4545
}()
4646
}
4747

test/expr/closure/closures.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func testSR13239_ArgsFn() -> Int {
690690
func testSR13239MultiExpr() -> Int {
691691
callit {
692692
print("hello")
693-
return print("hello") // expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
693+
return print("hello") // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
694694
}
695695
}
696696

@@ -734,19 +734,20 @@ public class TestImplicitCaptureOfExplicitCaptureOfSelfInEscapingClosure {
734734
}
735735

736736
// https://github.com/apple/swift/issues/59716
737+
// FIXME: Diagnostic should be tailored for closure result
737738
["foo"].map { s in
738-
if s == "1" { return } // expected-error{{cannot convert value of type '()' to closure result type 'Bool'}}
739+
if s == "1" { return } // expected-error{{cannot convert return expression of type '()' to return type 'Bool'}}
739740
return s.isEmpty
740741
}.filter { $0 }
741742

742743
["foo"].map { s in
743-
if s == "1" { return } // expected-error{{cannot convert value of type '()' to closure result type 'Bool'}}
744+
if s == "1" { return } // expected-error{{cannot convert return expression of type '()' to return type 'Bool'}}
744745
if s == "2" { return }
745746
if s == "3" { return }
746747
return s.isEmpty
747748
}.filter { $0 }
748749

749750
["foo"].map { s in
750-
if s == "1" { return () } // expected-error{{cannot convert value of type '()' to closure result type 'Bool'}}
751+
if s == "1" { return () } // expected-error{{cannot convert return expression of type '()' to return type 'Bool'}}
751752
return s.isEmpty
752753
}.filter { $0 }

0 commit comments

Comments
 (0)