mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix ref_struct.str() with null pointer (#14836)
This commit is contained in:
parent
587101a1ea
commit
e9a8f5fcc7
@ -111,7 +111,9 @@ 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=')
|
g.write('str_intp(1, _MOV((StrIntpData[]){{_SLIT("&"), $si_s_code ,{.d_s = isnil(')
|
||||||
|
g.expr(expr)
|
||||||
|
g.write(') ? _SLIT("nil") : ')
|
||||||
}
|
}
|
||||||
g.write('${str_fn_name}(')
|
g.write('${str_fn_name}(')
|
||||||
if str_method_expects_ptr && !is_ptr {
|
if str_method_expects_ptr && !is_ptr {
|
||||||
|
11
vlib/v/tests/string_ref_struct_test.v
Normal file
11
vlib/v/tests/string_ref_struct_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
struct Node {
|
||||||
|
val int
|
||||||
|
left &Node
|
||||||
|
right &Node
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_string_ref_struct() {
|
||||||
|
n := Node{123, 0, 0}
|
||||||
|
println(n.left)
|
||||||
|
assert '$n.left' == '&nil'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user