[Diagnostics] Add a tailored fix when ternary is associated with return

If it has been detected that there is an attempt to return a value
from a function without result type, let's diagnose that specifically
in cases when ternary operator is involved.
This commit is contained in:
Pavel Yaskevich
2020-07-10 11:22:33 -07:00
parent c3cc96829c
commit a49353b97b
2 changed files with 7 additions and 1 deletions

View File

@@ -4224,6 +4224,12 @@ bool ConstraintSystem::repairFailures(
if (hasFixFor(loc, FixKind::ContextualMismatch))
return true;
if (contextualType->isVoid() &&
getContextualTypePurpose(anchor) == CTP_ReturnStmt) {
conversionsOrFixes.push_back(RemoveReturn::create(*this, lhs, loc));
break;
}
conversionsOrFixes.push_back(
ContextualMismatch::create(*this, lhs, rhs, loc));
break;