mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix printing multi-reference struct (#16560)
This commit is contained in:
parent
fd04c1a03a
commit
c06696bc9a
@ -91,8 +91,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
|||||||
if expr !is ast.EnumVal {
|
if expr !is ast.EnumVal {
|
||||||
str_fn_name := g.get_str_fn(typ)
|
str_fn_name := g.get_str_fn(typ)
|
||||||
g.write('${str_fn_name}(')
|
g.write('${str_fn_name}(')
|
||||||
if typ.is_ptr() {
|
if typ.nr_muls() > 0 {
|
||||||
g.write('*')
|
g.write('*'.repeat(typ.nr_muls()))
|
||||||
}
|
}
|
||||||
g.enum_expr(expr)
|
g.enum_expr(expr)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
@ -107,7 +107,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
|||||||
is_var_mut := expr.is_auto_deref_var()
|
is_var_mut := expr.is_auto_deref_var()
|
||||||
str_fn_name := g.get_str_fn(typ)
|
str_fn_name := g.get_str_fn(typ)
|
||||||
if is_ptr && !is_var_mut {
|
if is_ptr && !is_var_mut {
|
||||||
g.write('str_intp(1, _MOV((StrIntpData[]){{_SLIT("&"), ${si_s_code} ,{.d_s = isnil(')
|
ref_str := '&'.repeat(typ.nr_muls())
|
||||||
|
g.write('str_intp(1, _MOV((StrIntpData[]){{_SLIT("${ref_str}"), ${si_s_code} ,{.d_s = isnil(')
|
||||||
g.expr(expr)
|
g.expr(expr)
|
||||||
g.write(') ? _SLIT("nil") : ')
|
g.write(') ? _SLIT("nil") : ')
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
|||||||
if str_method_expects_ptr && !is_ptr {
|
if str_method_expects_ptr && !is_ptr {
|
||||||
g.write('&')
|
g.write('&')
|
||||||
} else if !str_method_expects_ptr && !is_shared && (is_ptr || is_var_mut) {
|
} else if !str_method_expects_ptr && !is_shared && (is_ptr || is_var_mut) {
|
||||||
g.write('*')
|
g.write('*'.repeat(typ.nr_muls()))
|
||||||
}
|
}
|
||||||
if expr is ast.ArrayInit {
|
if expr is ast.ArrayInit {
|
||||||
if expr.is_fixed {
|
if expr.is_fixed {
|
||||||
|
3
vlib/v/tests/inout/printing_reference_struct.out
Normal file
3
vlib/v/tests/inout/printing_reference_struct.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
&AStruct{}
|
||||||
|
AStruct{}
|
||||||
|
&&AStruct{}
|
8
vlib/v/tests/inout/printing_reference_struct.vv
Normal file
8
vlib/v/tests/inout/printing_reference_struct.vv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
struct AStruct{}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
ast := &AStruct{}
|
||||||
|
println(ast)
|
||||||
|
println(*ast)
|
||||||
|
println(&ast)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user