diff --git a/vlib/v/gen/c/dumpexpr.v b/vlib/v/gen/c/dumpexpr.v index 96044445d9..9e8a1df1d0 100644 --- a/vlib/v/gen/c/dumpexpr.v +++ b/vlib/v/gen/c/dumpexpr.v @@ -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);') diff --git a/vlib/v/tests/inout/dump_nil_voidptr.out b/vlib/v/tests/inout/dump_nil_voidptr.out new file mode 100644 index 0000000000..be5cde440c --- /dev/null +++ b/vlib/v/tests/inout/dump_nil_voidptr.out @@ -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 diff --git a/vlib/v/tests/inout/dump_nil_voidptr.vv b/vlib/v/tests/inout/dump_nil_voidptr.vv new file mode 100644 index 0000000000..3f3dac554d --- /dev/null +++ b/vlib/v/tests/inout/dump_nil_voidptr.vv @@ -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) +}