cgen: fix if expr with optional method call (#14600)

yuyi 2022-06-03 20:57:39 +08:00 committed by Chewing_Bever
parent 4288c40bee
commit 9699afc1fd
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 15 additions and 1 deletions

View File

@ -29,7 +29,8 @@ fn (mut g Gen) need_tmp_var_in_if(node ast.IfExpr) bool {
if left_sym.kind in [.array, .array_fixed, .map] {
return true
}
} else if stmt.expr.or_block.kind != .absent {
}
if stmt.expr.or_block.kind != .absent {
return true
}
}

View File

@ -0,0 +1,13 @@
fn to_bit_string(i rune) []u8 {
return if i == 0 { []u8{} } else { '${i:b}'.split('').map(it.u8()) }
}
fn from_bit_string(bits []u8) rune {
return if bits == [] { 0 } else { bits.map(it.str()).join('').parse_uint(2, 8) or { 0 } }
}
fn test_if_expr_with_method_call_optional() {
a := from_bit_string(to_bit_string(u32(100)))
println(a)
assert a == `d`
}