1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix dump(nil), dump(voidptr) (fix #16455) (#16456)

This commit is contained in:
shove 2022-11-17 13:41:07 +08:00 committed by GitHub
parent 523ccbcb70
commit 49277f7aa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -74,6 +74,9 @@ fn (mut g Gen) dump_expr_definitions() {
surrounder.add('\tstring value = ${to_string_fn_name}();', '\tstring_free(&value);')
} else if dump_sym.kind == .none_ {
surrounder.add('\tstring value = _SLIT("none");', '\tstring_free(&value);')
} else if is_ptr {
surrounder.add('\tstring value = (dump_arg == NULL) ? _SLIT("nil") : ${to_string_fn_name}(${deref}dump_arg);',
'\tstring_free(&value);')
} else {
surrounder.add('\tstring value = ${to_string_fn_name}(${deref}dump_arg);',
'\tstring_free(&value);')

View File

@ -0,0 +1,2 @@
[vlib/v/tests/inout/dump_nil_voidptr.vv:11] a: &nil
[vlib/v/tests/inout/dump_nil_voidptr.vv:13] a: &nil

View File

@ -0,0 +1,14 @@
fn get_nil() ?&int {
return unsafe { nil }
}
fn get_voidptr() ?&int {
return voidptr(0)
}
fn main() {
mut a := get_nil()?
dump(a)
a = get_voidptr()?
dump(a)
}