mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix printing reference alias (#15027)
This commit is contained in:
parent
ec19f4289c
commit
398bd2280d
@ -126,9 +126,13 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||
g.write('}}}))')
|
||||
}
|
||||
} else {
|
||||
is_ptr := typ.is_ptr()
|
||||
is_var_mut := expr.is_auto_deref_var()
|
||||
str_fn_name := g.get_str_fn(typ)
|
||||
g.write('${str_fn_name}(')
|
||||
if expr.is_auto_deref_var() {
|
||||
if str_method_expects_ptr && !is_ptr {
|
||||
g.write('&')
|
||||
} else if (!str_method_expects_ptr && is_ptr && !is_shared) || is_var_mut {
|
||||
g.write('*')
|
||||
}
|
||||
if sym.kind != .function {
|
||||
|
6
vlib/v/tests/inout/printing_reference_alias.out
Normal file
6
vlib/v/tests/inout/printing_reference_alias.out
Normal file
@ -0,0 +1,6 @@
|
||||
Point(Quad{
|
||||
x: 1
|
||||
y: 2
|
||||
z: 3
|
||||
w: 1
|
||||
})
|
23
vlib/v/tests/inout/printing_reference_alias.vv
Normal file
23
vlib/v/tests/inout/printing_reference_alias.vv
Normal file
@ -0,0 +1,23 @@
|
||||
struct Quad {
|
||||
mut:
|
||||
x f64
|
||||
y f64
|
||||
z f64
|
||||
w f64
|
||||
}
|
||||
|
||||
type Point = Quad
|
||||
type Vector = Quad
|
||||
|
||||
fn new_point(x f64, y f64, z f64) &Point {
|
||||
return &Point{x, y, z, 1}
|
||||
}
|
||||
|
||||
fn new_vector(x f64, y f64, z f64) &Vector {
|
||||
return &Vector{x, y, z, 0}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
n := new_point(1, 2, 3)
|
||||
println(n)
|
||||
}
|
Loading…
Reference in New Issue
Block a user