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

master
yuyi 2022-06-03 20:57:39 +08:00 committed by GitHub
parent 65066098d8
commit dcbd8d6405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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] { if left_sym.kind in [.array, .array_fixed, .map] {
return true return true
} }
} else if stmt.expr.or_block.kind != .absent { }
if stmt.expr.or_block.kind != .absent {
return true 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`
}