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/type_test.v',
|
||||||
'vlib/v/tests/typeof_test.v',
|
'vlib/v/tests/typeof_test.v',
|
||||||
'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only
|
'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.expr(node.args[0].expr)
|
||||||
g.writeln('); ${print_method}($tmp); string_free($tmp); //MEM2 $styp')
|
g.writeln('); ${print_method}($tmp); string_free($tmp); //MEM2 $styp')
|
||||||
} else {
|
} else {
|
||||||
// println(var) or println println(str.var)
|
|
||||||
expr := node.args[0].expr
|
expr := node.args[0].expr
|
||||||
is_var := match expr {
|
is_var := match expr {
|
||||||
ast.SelectorExpr {
|
ast.SelectorExpr {
|
||||||
|
@ -2575,11 +2574,9 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// `println(int_str(10))`
|
if table.type_is_ptr(typ) && sym.kind != .struct_ {
|
||||||
// sym := g.table.get_type_symbol(node.args[0].typ)
|
|
||||||
if table.type_is_ptr(typ) {
|
|
||||||
// ptr_str() for pointers
|
// ptr_str() for pointers
|
||||||
// styp = 'ptr'
|
styp = 'ptr'
|
||||||
}
|
}
|
||||||
if sym.kind == .enum_ {
|
if sym.kind == .enum_ {
|
||||||
if is_var {
|
if is_var {
|
||||||
|
@ -2599,7 +2596,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g.write('${print_method}(${styp}_str(')
|
g.write('${print_method}(${styp}_str(')
|
||||||
if table.type_is_ptr(typ) {
|
if table.type_is_ptr(typ) && sym.kind == .struct_ {
|
||||||
// dereference
|
// dereference
|
||||||
g.write('*')
|
g.write('*')
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,4 @@ yellow
|
||||||
green
|
green
|
||||||
green
|
green
|
||||||
interp: green
|
interp: green
|
||||||
interp: green
|
interp: green
|
||||||
orange
|
|
|
@ -11,10 +11,6 @@ struct A{
|
||||||
color Color
|
color Color
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (c &Color) test() {
|
|
||||||
println(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
col := Color.green
|
col := Color.green
|
||||||
a := A{color: col}
|
a := A{color: col}
|
||||||
|
@ -25,5 +21,4 @@ fn main() {
|
||||||
println(a.color)
|
println(a.color)
|
||||||
println('interp: ${col}')
|
println('interp: ${col}')
|
||||||
println('interp: ${a.color}')
|
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