Skip to content

Commit

Permalink
cgen: fix error for generics struct that parent has str to string (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Apr 14, 2022
1 parent f6c9a60 commit 72c2dc8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/gen/c/auto_str_methods.v
Expand Up @@ -896,7 +896,12 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
sftyp := g.typ(field.typ)
mut field_styp := sftyp.replace('*', '')
field_styp_fn_name := if sym_has_str_method {
'${field_styp}_str'
mut field_fn_name := '${field_styp}_str'
if sym.info is ast.Struct {
field_fn_name = g.generic_fn_name(sym.info.concrete_types, field_fn_name,
false)
}
field_fn_name
} else {
g.get_str_fn(field.typ)
}
Expand Down
36 changes: 36 additions & 0 deletions vlib/v/tests/generics_struct_parent_has_str_to_string_test.v
@@ -0,0 +1,36 @@
import datatypes

const (
w = 64
h = 32
)

interface Display {
mut:
pixel(x int, y int, val bool)
clear()
refresh()
}

struct Vm {
mut:
display Display
stack datatypes.Stack<u16>
}

struct Pattern {
pattern []byte
handler fn (mut m Vm)
}

fn new_pattern(pattern string, handler fn (mut m Vm)) Pattern {
return Pattern{pattern.runes().map(byte('0x$it'.int())), handler}
}

fn test_generics_struct_parent_has_str_to_string() {
p := new_pattern('00E0', fn (mut m Vm) {
println(m)
})
println(p)
assert true
}

0 comments on commit 72c2dc8

Please sign in to comment.