Skip to content

Commit

Permalink
HIR/MIR - Handle break return properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 5, 2024
1 parent 53fc21d commit 15b827f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/hir_typeck/expr_cs__enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ namespace typecheck
if( node.m_value ) {
this->context.add_ivars(node.m_value->m_res_type);
node.m_value->visit(*this);
this->context.equate_types(node.span(), loop_node.m_res_type, node.m_value->m_res_type);
this->context.equate_types_coerce(node.span(), loop_node.m_res_type, node.m_value);
this->context.require_sized(node.span(), node.m_value->m_res_type);
}
else {
Expand Down
15 changes: 11 additions & 4 deletions src/mir/from_hir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@ namespace {
ASSERT_BUG(node.span(), !node.m_continue, "Continue with a value isn't valid");
DEBUG("break value;");
this->visit_node_ptr(node.m_value);
//if( m_builder.resolve().type_is_impossible(node.span(), node.m_value->m_res_type) ) {
if( node.m_value->m_res_type.data().is_Diverge() ) {
//ASSERT_BUG(node.span(), !m_builder.has_result(), "Result present when value type is uninhabited - " << node.m_value->m_res_type);
//ASSERT_BUG(node.span(), !m_builder.block_active(), "Result present when value type is uninhabited - " << node.m_value->m_res_type);
}
}
if( !m_builder.block_active() ) {
// No block is currently active, not worth running the rest
return ;
}

// TODO: Use node.m_target_node
Expand All @@ -815,12 +824,10 @@ namespace {
m_builder.end_block( ::MIR::Terminator::make_Goto(target_block.cur) );
}
else {
if( node.m_value )
{
if( node.m_value ) {
m_builder.push_stmt_assign( node.span(), target_block.res_value.clone(), m_builder.get_result(node.span()) );
}
else
{
else {
// Set result to ()
m_builder.push_stmt_assign( node.span(), target_block.res_value.clone(), ::MIR::RValue::make_Tuple({{}}) );
}
Expand Down

0 comments on commit 15b827f

Please sign in to comment.