Skip to content

Commit

Permalink
cgen: fix _str name generated for C struct which define str() method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Mar 18, 2024
1 parent bedaf4f commit 8e9ddb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/gen/c/auto_str_methods.v
Expand Up @@ -83,6 +83,9 @@ fn (mut g Gen) get_str_fn(typ ast.Type) string {
else {}
}
}
if sym.language == .c && !typ.has_flag(.option) && sym.has_method('str') {
str_fn_name = util.no_dots(g.cc_type(unwrapped, false)) + '_str'
}
g.str_types << StrType{
typ: unwrapped
styp: styp
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/tests/c_structs/cstruct.h
@@ -0,0 +1,4 @@

struct Abc {
int field;
};
17 changes: 17 additions & 0 deletions vlib/v/tests/c_structs/cstruct_test.c.v
@@ -0,0 +1,17 @@
#include "@VMODROOT/cstruct.h"

const the_string = 'the string'

pub struct C.Abc {
field int
}

fn (a &C.Abc) str() string {
return 'C.Abc{}'
}

fn test_cstruct() {
x := unsafe { &C.Abc(1) }
println(x)
assert dump(x.str()) == 'C.Abc{}'
}
Empty file added vlib/v/tests/c_structs/v.mod
Empty file.

0 comments on commit 8e9ddb1

Please sign in to comment.