checker: fix if expr infix (#8215)

* checker: fix if expr infix

* remove debugger code

* fmt

* remove debug

* add test cases
pull/8245/head
Daniel Däschle 2021-01-21 12:42:24 +01:00 committed by GitHub
parent 29b3077ea1
commit c6d6690064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -704,7 +704,6 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
defer {
c.expected_type = former_expected_type
}
c.expected_type = table.void_type
left_type := c.expr(infix_expr.left)
// left_type = c.unwrap_genric(c.expr(infix_expr.left))
infix_expr.left_type = left_type

View File

@ -157,3 +157,13 @@ fn test_lots_of_if_expressions() {
}
assert a == 1
}
fn test_if_expr_with_infix() {
a := if true { 1 } else { 0 } + 5
assert a == 6
}
fn test_multi_if_expr_with_infix() {
a := if 1 == 0 { 1 } else if 1 == 0 { 2 } else { 3 } + 4
assert a == 7
}

View File

@ -268,3 +268,8 @@ fn test_sumtype_with_array() {
}
}
}
fn test_match_expression_add() {
a := match true { true {1} false {2} } + 3
assert a == 4
}