cgen: printing pointer should print the address
parent
f508955b64
commit
c0d86eb651
|
@ -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',
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -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('*')
|
||||
}
|
||||
|
|
|
@ -3,5 +3,4 @@ yellow
|
|||
green
|
||||
green
|
||||
interp: green
|
||||
interp: green
|
||||
orange
|
||||
interp: green
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
struct A {
|
||||
foo int
|
||||
}
|
||||
|
||||
fn test_pointer_to_string() {
|
||||
a := A{}
|
||||
assert a.foo.str() != (&a.foo).str()
|
||||
}
|
Loading…
Reference in New Issue