Skip to content

Commit a38fc3d

Browse files
authored
Merge pull request #59415 from xedin/issue-59390
[Diagnostics] Diagnose a mismatch between result builder result and r…
2 parents 22f90f6 + 63fcd67 commit a38fc3d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,6 +6179,10 @@ ERROR(result_builder_requires_explicit_var_initialization,none,
61796179
ERROR(cannot_declare_computed_var_in_result_builder,none,
61806180
"cannot declare local %select{lazy|wrapped|computed|observed}0 variable "
61816181
"in result builder", (unsigned))
6182+
ERROR(cannot_convert_result_builder_result_to_return_type,none,
6183+
"cannot convert result builder result type %0 to return type %1",
6184+
(Type,Type))
6185+
61826186

61836187
//------------------------------------------------------------------------------
61846188
// MARK: Tuple Shuffle Diagnostics

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
796796
break;
797797
}
798798

799+
case ConstraintLocator::ResultBuilderBodyResult:
800+
diagnostic = diag::cannot_convert_result_builder_result_to_return_type;
801+
break;
802+
799803
case ConstraintLocator::AutoclosureResult:
800804
case ConstraintLocator::ApplyArgToParam:
801805
case ConstraintLocator::ApplyArgument: {

test/Constraints/result_builder_diags.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,20 @@ func test_rdar89742267() {
838838
}
839839
}
840840
}
841+
842+
// https://github.com/apple/swift/issues/59390
843+
func test_invalid_result_is_diagnosed() {
844+
@resultBuilder
845+
struct MyBuilder {
846+
static func buildBlock<T1>(_ t1: T1) -> T1 {
847+
return t1
848+
}
849+
}
850+
851+
struct S<T> {} // expected-note {{arguments to generic parameter 'T' ('Int' and 'String') are expected to be equal}}
852+
853+
@MyBuilder
854+
func test() -> S<String> { // expected-error {{cannot convert result builder result type 'S<Int>' to return type 'S<String>}}
855+
S<Int>()
856+
}
857+
}

0 commit comments

Comments
 (0)