diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-19 14:47:01 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-20 10:02:14 +0000 |
commit | 76b308af7e69f5b50fee96ba4b3584935e621259 (patch) | |
tree | 2c98289d813b6fc133c989ae2e0de6b7a25348f4 /gcc/rust | |
parent | 23edde6fef4321d30f9f2f8c75e6cbfd59b75ca4 (diff) | |
download | gcc-76b308af7e69f5b50fee96ba4b3584935e621259.zip gcc-76b308af7e69f5b50fee96ba4b3584935e621259.tar.gz gcc-76b308af7e69f5b50fee96ba4b3584935e621259.tar.bz2 |
ComparisonExprs and LazyBoolExprs are bools
This fixes the expression type resolution to coerce these into bools. For
LazyBoolExprs && and || the lhs and rhs are bools.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index dfa319b..c47e0ec 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -376,7 +376,12 @@ public: auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); - infered = lhs->combine (rhs); + auto result = lhs->combine (rhs); + if (result == nullptr || result->get_kind () == TyTy::TypeKind::ERROR) + return; + + // we expect this to be + infered = new TyTy::BoolType (expr.get_mappings ().get_hirid ()); } void visit (HIR::LazyBooleanExpr &expr) @@ -384,8 +389,18 @@ public: auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); + // we expect the lhs and rhs must be bools at this point + TyTy::BoolType elhs (expr.get_mappings ().get_hirid ()); + lhs = elhs.combine (lhs); + if (lhs == nullptr || lhs->get_kind () == TyTy::TypeKind::ERROR) + return; + + TyTy::BoolType rlhs (expr.get_mappings ().get_hirid ()); + rhs = elhs.combine (rhs); + if (lhs == nullptr || lhs->get_kind () == TyTy::TypeKind::ERROR) + return; + infered = lhs->combine (rhs); - // FIXME this will need to turn into bool } void visit (HIR::IfExpr &expr) |