1
0
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:
yuyi 2022-06-23 13:35:21 +08:00 committed by GitHub
parent 587101a1ea
commit e9a8f5fcc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

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

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