diff options
author | Jakub Dupak <dev@jakubdupak.com> | 2023-10-16 15:28:03 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2023-10-20 08:35:27 +0000 |
commit | 8ad583020b0279f02edd76d2512c36c56977ec41 (patch) | |
tree | 65d74ca3c171ebf047f97fa2363bb7b27da4f0d3 | |
parent | 155458a12597155e5c35a34de8ad9cd1ce72a874 (diff) | |
download | gcc-8ad583020b0279f02edd76d2512c36c56977ec41.zip gcc-8ad583020b0279f02edd76d2512c36c56977ec41.tar.gz gcc-8ad583020b0279f02edd76d2512c36c56977ec41.tar.bz2 |
typecheck: add loop ctx for labelled block
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 805c4bb..3a63d3b 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -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 ()) @@ -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 |