parent
32091dd90e
commit
93262353d6
|
@ -367,6 +367,17 @@ fn test_map_in_mut() {
|
|||
assert m['one'] == 2
|
||||
}
|
||||
|
||||
fn test_map_in() {
|
||||
m := {
|
||||
'Foo': 'bar'
|
||||
}
|
||||
if 'foo'.capitalize() in m {
|
||||
println('ok')
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
fn mut_map_with_relation_op_in_fn(mut m map[string]int) {
|
||||
if m['one'] == 1 {
|
||||
m['three'] = 3
|
||||
|
|
|
@ -3081,12 +3081,22 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
|
|||
return
|
||||
} else if right_sym.kind == .map {
|
||||
g.write('_IN_MAP(')
|
||||
g.expr(node.left)
|
||||
g.write(', ')
|
||||
if node.right_type.is_ptr() {
|
||||
g.write('*')
|
||||
if !node.left_type.is_ptr() {
|
||||
left_type_str := g.table.type_to_str(node.left_type)
|
||||
g.write('ADDR($left_type_str, ')
|
||||
g.expr(node.left)
|
||||
g.write(')')
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
}
|
||||
g.write(', ')
|
||||
if !node.right_type.is_ptr() {
|
||||
g.write('ADDR(map, ')
|
||||
g.expr(node.right)
|
||||
g.write(')')
|
||||
} else {
|
||||
g.expr(node.right)
|
||||
}
|
||||
g.expr(node.right)
|
||||
g.write(')')
|
||||
} else if right_sym.kind == .string {
|
||||
g.write('string_contains(')
|
||||
|
|
|
@ -272,7 +272,7 @@ static void* g_live_info = NULL;
|
|||
// take the address of an rvalue
|
||||
#define ADDR(type, expr) (&((type[]){expr}[0]))
|
||||
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
|
||||
#define _IN_MAP(val, m) map_exists_1(&m, &val)
|
||||
#define _IN_MAP(val, m) map_exists_1(m, val)
|
||||
|
||||
// unsigned/signed comparisons
|
||||
static inline bool _us32_gt(uint32_t a, int32_t b) { return a > INT32_MAX || (int32_t)a > b; }
|
||||
|
|
Loading…
Reference in New Issue