mirror of
https://github.com/oxalica/nil.git
synced 2025-12-23 09:19:49 +00:00
Fix type for condition expr of if
This commit is contained in:
parent
f43380d009
commit
1e3fdf59cb
2 changed files with 3 additions and 1 deletions
|
|
@ -208,7 +208,8 @@ impl<'db> InferCtx<'db> {
|
|||
self.infer_expr(body)
|
||||
}
|
||||
&Expr::IfThenElse(cond, then, else_) => {
|
||||
self.infer_expr(cond);
|
||||
let cond_ty = self.infer_expr(cond);
|
||||
self.unify_kind(cond_ty, TyKind::Bool);
|
||||
let then_ty = self.infer_expr(then);
|
||||
let else_ty = self.infer_expr(else_);
|
||||
self.unify(then_ty, else_ty);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ fn recursive() {
|
|||
|
||||
#[test]
|
||||
fn if_then_else() {
|
||||
check("a: if a then 1 else 1", expect!["bool → int"]);
|
||||
check(
|
||||
"if 1 == 2 then { a = 1; } else { b = 1; }",
|
||||
expect!["{ a: int, b: int }"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue