public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] type check
@ 2022-06-08 12:49 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ec9a03a03b512e268dd31571df18e2c37e1ee372

commit ec9a03a03b512e268dd31571df18e2c37e1ee372
Author: antego <antego@users.noreply.github.com>
Date:   Thu May 12 21:32:53 2022 +1000

    type check

Diff:
---
 gcc/rust/hir/tree/rust-hir-expr.h             | 13 +++++++++++++
 gcc/rust/typecheck/rust-hir-type-check-expr.h | 23 +++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index f6f035e2134..789ad78ffa2 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3477,6 +3477,19 @@ public:
   void accept_vis (HIRFullVisitor &vis) override;
   void accept_vis (HIRExpressionVisitor &vis) override;
 
+  std::unique_ptr<Expr> &get_scrutinee_expr ()
+  {
+    rust_assert (value != nullptr);
+    return value;
+  }
+
+  std::vector<std::unique_ptr<Pattern> > &get_patterns ()
+  {
+    return match_arm_patterns;
+  }
+
+  BlockExpr *get_if_block () { return if_block.get (); }
+
   ExprType get_expression_type () const final override
   {
     return ExprType::IfLet;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index b20a048865d..411d45de41f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -703,6 +703,29 @@ public:
       infered = if_blk_resolved->unify (else_blk_resolved);
   }
 
+  void visit (HIR::IfLetExpr &expr) override
+  {
+    // this needs to perform a least upper bound coercion on the blocks and then
+    // unify the scruintee and arms
+    TyTy::BaseType *scrutinee_tyty
+      = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get (), false);
+
+    for (auto &pattern : expr.get_patterns ())
+      {
+	TyTy::BaseType *kase_arm_ty
+	  = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty);
+
+	TyTy::BaseType *checked_kase = scrutinee_tyty->unify (kase_arm_ty);
+	if (checked_kase->get_kind () == TyTy::TypeKind::ERROR)
+	  return;
+      }
+
+    TypeCheckExpr::Resolve (expr.get_if_block (), inside_loop);
+
+    infered
+      = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+  }
+
   void visit (HIR::BlockExpr &expr) override;
 
   void visit (HIR::UnsafeBlockExpr &expr) override


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:49 [gcc/devel/rust/master] type check Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).