@@ -3374,19 +3374,21 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
33743374 if (auto ret = dyn_cast_or_null<ReturnStmt>(
33753375 caseLabel->getBody ()->getSingleActiveElement ()
33763376 .dyn_cast <Stmt*>())) {
3377- Expr *result = ret->getResult ()->getSemanticsProvidingExpr ();
3378- if (result->getType ()->isNoncopyable ()) {
3379- while (auto conv = dyn_cast<ImplicitConversionExpr>(result)) {
3380- result = conv->getSubExpr ()->getSemanticsProvidingExpr ();
3381- }
3382- if (auto dr = dyn_cast<DeclRefExpr>(result)) {
3383- if (std::find (caseLabel->getCaseBodyVariables ().begin (),
3384- caseLabel->getCaseBodyVariables ().end (),
3385- dr->getDecl ())
3386- != caseLabel->getCaseBodyVariables ().end ()) {
3387- SGM.diagnose (result->getLoc (),
3388- diag::return_borrowing_switch_binding);
3389- ownership = ValueOwnership::Owned;
3377+ if (ret->hasResult ()) {
3378+ Expr *result = ret->getResult ()->getSemanticsProvidingExpr ();
3379+ if (result->getType ()->isNoncopyable ()) {
3380+ while (auto conv = dyn_cast<ImplicitConversionExpr>(result)) {
3381+ result = conv->getSubExpr ()->getSemanticsProvidingExpr ();
3382+ }
3383+ if (auto dr = dyn_cast<DeclRefExpr>(result)) {
3384+ if (std::find (caseLabel->getCaseBodyVariables ().begin (),
3385+ caseLabel->getCaseBodyVariables ().end (),
3386+ dr->getDecl ())
3387+ != caseLabel->getCaseBodyVariables ().end ()) {
3388+ SGM.diagnose (result->getLoc (),
3389+ diag::return_borrowing_switch_binding);
3390+ ownership = ValueOwnership::Owned;
3391+ }
33903392 }
33913393 }
33923394 }
0 commit comments