1
0
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:
yuyi 2022-07-12 01:04:34 +08:00 committed by GitHub
parent ec19f4289c
commit 398bd2280d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View File

@ -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 {

View File

@ -0,0 +1,6 @@
Point(Quad{
x: 1
y: 2
z: 3
w: 1
})

View 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)
}