@@ -2958,10 +2958,11 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) {
29582958 ConvertCondition (expr->getCond ());
29592959 bool branch_is_addr =
29602960 expr->isLValue () && !isRValue () && !expr->getType ()->isFunctionType ();
2961+ bool branch_is_mut = curr_init_type_.empty () || IsMut (curr_init_type_.back ());
29612962 {
29622963 PushBrace then_brace (*this );
29632964 if (branch_is_addr) {
2964- StrCat (token::kRef , keyword_mut_);
2965+ StrCat (token::kRef , branch_is_mut ? keyword_mut_ : " " );
29652966 }
29662967 PushExplicitAutoref no_autoref (*this , branch_is_addr ? std::nullopt
29672968 : autoref_mut_);
@@ -2973,7 +2974,7 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) {
29732974 {
29742975 PushBrace else_brace (*this );
29752976 if (branch_is_addr) {
2976- StrCat (token::kRef , keyword_mut_);
2977+ StrCat (token::kRef , branch_is_mut ? keyword_mut_ : " " );
29772978 }
29782979 PushExplicitAutoref no_autoref (*this , branch_is_addr ? std::nullopt
29792980 : autoref_mut_);
@@ -4190,6 +4191,18 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) {
41904191 StrCat (EmitMaterializedTempBinding (qual_type, expr));
41914192 return ;
41924193 }
4194+ if (auto *cond = clang::dyn_cast<clang::ConditionalOperator>(
4195+ expr->IgnoreParenImpCasts ());
4196+ cond && cond->isLValue ()) {
4197+ {
4198+ PushExprKind push (*this , ExprKind::LValue);
4199+ PushInitType init_type (*this , qual_type);
4200+ Convert (cond);
4201+ }
4202+ StrCat (keyword::kAs );
4203+ Convert (qual_type);
4204+ return ;
4205+ }
41934206 StrCat (token::kRef );
41944207 if (IsMut (qual_type)) {
41954208 StrCat (keyword_mut_);
0 commit comments