cgen: printing pointer should print the address

pull/4321/head
Daniel Däschle 2020-04-09 15:35:52 +02:00 committed by GitHub
parent f508955b64
commit c0d86eb651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 13 deletions

View File

@ -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',
]
)

View File

@ -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('*')
}

View File

@ -3,5 +3,4 @@ yellow
green
green
interp: green
interp: green
orange
interp: green

View File

@ -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()
}

View File

@ -0,0 +1,8 @@
struct A {
foo int
}
fn test_pointer_to_string() {
a := A{}
assert a.foo.str() != (&a.foo).str()
}