Skip to content

Commit a59b8be

Browse files
committed
[Diagnostics] Detect that return type mismatch belongs to a result builder
Since result builders are now type-checked like regular closures diagnostics have to detect that contextual result type mismatch occured in `return` statement associated with result builder transformed function/closure.
1 parent ad34bdd commit a59b8be

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,20 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
809809
}
810810
}
811811

812+
if (purpose == CTP_ReturnStmt) {
813+
if (auto *DRE = getAsExpr<DeclRefExpr>(anchor)) {
814+
auto *decl = DRE->getDecl();
815+
if (decl && decl->hasName()) {
816+
auto baseName = DRE->getDecl()->getBaseIdentifier();
817+
if (baseName.str().startswith("$__builder")) {
818+
diagnostic =
819+
diag::cannot_convert_result_builder_result_to_return_type;
820+
break;
821+
}
822+
}
823+
}
824+
}
825+
812826
diagnostic = getDiagnosticFor(purpose);
813827
break;
814828
}

0 commit comments

Comments
 (0)