cgen: fix invalid operands to `an_alias in an_array_of_aliased_values` (#13994)

pull/14007/head
牧心 2022-04-10 16:42:17 +08:00 committed by GitHub
parent 8517b8f8b0
commit 11d9a67e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -293,3 +293,10 @@ fn test_can_copy_bits() {
// map not copyable
assert !can_copy_bits<map[string]int>()
}
type Str = string
fn test_alias_string_contains() {
names := [Str('')]
assert (Str('') in names) == true
}

View File

@ -673,7 +673,11 @@ fn (mut g Gen) gen_array_contains_methods() {
fn_name := '${left_type_str}_contains'
left_info := left_final_sym.info as ast.Array
mut elem_type_str := g.typ(left_info.elem_type)
elem_sym := g.table.sym(left_info.elem_type)
mut elem_sym := g.table.sym(left_info.elem_type)
if elem_sym.kind == .alias {
info := elem_sym.info as ast.Alias
elem_sym = g.table.sym(info.parent_type)
}
if elem_sym.kind == .function {
left_type_str = 'Array_voidptr'
elem_type_str = 'voidptr'
@ -751,7 +755,11 @@ fn (mut g Gen) gen_array_index_methods() {
fn_name := '${left_type_str}_index'
info := final_left_sym.info as ast.Array
mut elem_type_str := g.typ(info.elem_type)
elem_sym := g.table.sym(info.elem_type)
mut elem_sym := g.table.sym(info.elem_type)
if elem_sym.kind == .alias {
info_t := elem_sym.info as ast.Alias
elem_sym = g.table.sym(info_t.parent_type)
}
if elem_sym.kind == .function {
left_type_str = 'Array_voidptr'
elem_type_str = 'voidptr'