Skip to content

Commit

Permalink
typecheck: add loop ctx for labelled block
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx.

Signed-off-by: Jakub Dupak <[email protected]>
  • Loading branch information
jdupak authored and P-E-P committed Oct 20, 2023
1 parent 155458a commit 8ad5830
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr)
void
TypeCheckExpr::visit (HIR::BlockExpr &expr)
{
if (expr.has_label ())
context->push_new_loop_context (expr.get_mappings ().get_hirid (),
expr.get_locus ());

for (auto &s : expr.get_statements ())
{
if (!s->is_item ())
Expand Down Expand Up @@ -602,6 +606,20 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
else if (expr.is_tail_reachable ())
infered
= TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
else if (expr.has_label ())
{
TyTy::BaseType *loop_context_type = context->pop_loop_context ();

bool loop_context_type_infered
= (loop_context_type->get_kind () != TyTy::TypeKind::INFER)
|| ((loop_context_type->get_kind () == TyTy::TypeKind::INFER)
&& (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
!= TyTy::InferType::GENERAL));

infered = loop_context_type_infered ? loop_context_type
: TyTy::TupleType::get_unit_type (
expr.get_mappings ().get_hirid ());
}
else
{
// FIXME this seems wrong
Expand Down

0 comments on commit 8ad5830

Please sign in to comment.