cgen: fix enum in map (#9912)

pull/9921/head
ka-weihe 2021-04-28 21:11:32 +02:00 committed by GitHub
parent a065d014a2
commit 6795b02e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -617,6 +617,15 @@ type ColorAlias = Color
fn test_alias_enum() { fn test_alias_enum() {
mut m := map[ColorAlias]string{} mut m := map[ColorAlias]string{}
m[Color.red] = 'hi' m[Color.red] = 'hi'
assert m[Color.red] == 'hi'
}
fn test_enum_in_map() {
mut m := map[Color]string{}
m[Color.red] = 'hi'
assert Color.red in m
assert Color.green !in m
assert Color.blue !in m
} }
fn test_voidptr_keys() { fn test_voidptr_keys() {

View File

@ -3537,8 +3537,8 @@ fn (mut g Gen) infix_in_or_not_in(node ast.InfixExpr, left_sym ast.TypeSymbol, r
} else if right_sym.kind == .map { } else if right_sym.kind == .map {
g.write('_IN_MAP(') g.write('_IN_MAP(')
if !node.left_type.is_ptr() { if !node.left_type.is_ptr() {
left_type_str := g.table.type_to_str(node.left_type) styp := g.typ(node.left_type)
g.write('ADDR($left_type_str, ') g.write('ADDR($styp, ')
g.expr(node.left) g.expr(node.left)
g.write(')') g.write(')')
} else { } else {