cgen: fix generation of array names in generic structs (#7324)

pull/7333/head
Swastik Baranwal 2020-12-14 21:22:20 +05:30 committed by GitHub
parent 4f986ccac4
commit a3c3fd4d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -530,7 +530,7 @@ fn (g &Gen) cc_type2(t table.Type) string {
mut sgtyps := '_T'
for gt in sym.info.generic_types {
gts := g.table.get_type_symbol(if gt.has_flag(.generic) { g.unwrap_generic(gt) } else { gt })
sgtyps += '_$gts.name'
sgtyps += '_$gts.cname'
}
styp += sgtyps
}

View File

@ -387,7 +387,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) table.Type {
}
gts := p.table.get_type_symbol(gt)
bs_name += gts.name
bs_cname += gts.name
bs_cname += gts.cname
generic_types << gt
if p.tok.kind != .comma {
break

View File

@ -288,6 +288,14 @@ fn test_struct_from_other_module() {
assert g.msg.name == ''
}
fn test_generic_struct_print_array_as_field() {
foo := Foo<[]string>{
data: []string{}
}
assert foo.str() == 'Foo<array, string>{\n data: []\n}'
}
/*
struct Abc{ x int y int z int }