diff --git a/cmd/tools/vtest-fixed.v b/cmd/tools/vtest-fixed.v index 28c538240f..bf6a01c88f 100644 --- a/cmd/tools/vtest-fixed.v +++ b/cmd/tools/vtest-fixed.v @@ -52,6 +52,7 @@ const ( 'vlib/v/tests/type_test.v', 'vlib/v/tests/typeof_test.v', 'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only + 'vlib/v/tests/pointers_str_test.v', ] ) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index a115f76ffd..0423486733 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2562,7 +2562,6 @@ fn (g mut Gen) fn_call(node ast.CallExpr) { g.expr(node.args[0].expr) g.writeln('); ${print_method}($tmp); string_free($tmp); //MEM2 $styp') } else { - // println(var) or println println(str.var) expr := node.args[0].expr is_var := match expr { ast.SelectorExpr { @@ -2575,11 +2574,9 @@ fn (g mut Gen) fn_call(node ast.CallExpr) { false } } - // `println(int_str(10))` - // sym := g.table.get_type_symbol(node.args[0].typ) - if table.type_is_ptr(typ) { + if table.type_is_ptr(typ) && sym.kind != .struct_ { // ptr_str() for pointers - // styp = 'ptr' + styp = 'ptr' } if sym.kind == .enum_ { if is_var { @@ -2599,7 +2596,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) { } } else { g.write('${print_method}(${styp}_str(') - if table.type_is_ptr(typ) { + if table.type_is_ptr(typ) && sym.kind == .struct_ { // dereference g.write('*') } diff --git a/vlib/v/tests/inout/enum_print.out b/vlib/v/tests/inout/enum_print.out index 440b18edf6..362ee21355 100644 --- a/vlib/v/tests/inout/enum_print.out +++ b/vlib/v/tests/inout/enum_print.out @@ -3,5 +3,4 @@ yellow green green interp: green -interp: green -orange \ No newline at end of file +interp: green \ No newline at end of file diff --git a/vlib/v/tests/inout/enum_print.vv b/vlib/v/tests/inout/enum_print.vv index a68470d0b2..77bb301350 100644 --- a/vlib/v/tests/inout/enum_print.vv +++ b/vlib/v/tests/inout/enum_print.vv @@ -11,10 +11,6 @@ struct A{ color Color } -fn (c &Color) test() { - println(c) -} - fn main() { col := Color.green a := A{color: col} @@ -25,5 +21,4 @@ fn main() { println(a.color) println('interp: ${col}') println('interp: ${a.color}') - orange.test() } diff --git a/vlib/v/tests/pointers_str_test.v b/vlib/v/tests/pointers_str_test.v new file mode 100644 index 0000000000..101cdcbecb --- /dev/null +++ b/vlib/v/tests/pointers_str_test.v @@ -0,0 +1,8 @@ +struct A { + foo int +} + +fn test_pointer_to_string() { + a := A{} + assert a.foo.str() != (&a.foo).str() +}