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

cgen: fix dump(none) (#16287)

This commit is contained in:
yuyi 2022-11-02 20:21:28 +08:00 committed by GitHub
parent 7bd00b7580
commit 54b6b43922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -45,7 +45,12 @@ fn (mut g Gen) dump_expr_definitions() {
deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type) deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type)
to_string_fn_name := g.get_str_fn(typ.clear_flag(.shared_f)) to_string_fn_name := g.get_str_fn(typ.clear_flag(.shared_f))
ptr_asterisk := if is_ptr { '*'.repeat(typ.nr_muls()) } else { '' } ptr_asterisk := if is_ptr { '*'.repeat(typ.nr_muls()) } else { '' }
mut str_dumparg_type := g.cc_type(dump_type, true) + ptr_asterisk mut str_dumparg_type := ''
if dump_sym.kind == .none_ {
str_dumparg_type = 'IError' + ptr_asterisk
} else {
str_dumparg_type = g.cc_type(dump_type, true) + ptr_asterisk
}
if dump_sym.kind == .function { if dump_sym.kind == .function {
fninfo := dump_sym.info as ast.FnType fninfo := dump_sym.info as ast.FnType
str_dumparg_type = 'DumpFNType_$name' str_dumparg_type = 'DumpFNType_$name'
@ -67,6 +72,8 @@ fn (mut g Gen) dump_expr_definitions() {
surrounder.add('\tstring sline = int_str(line);', '\tstring_free(&sline);') surrounder.add('\tstring sline = int_str(line);', '\tstring_free(&sline);')
if dump_sym.kind == .function { if dump_sym.kind == .function {
surrounder.add('\tstring value = ${to_string_fn_name}();', '\tstring_free(&value);') 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 { } else {
surrounder.add('\tstring value = ${to_string_fn_name}(${deref}dump_arg);', surrounder.add('\tstring value = ${to_string_fn_name}(${deref}dump_arg);',
'\tstring_free(&value);') '\tstring_free(&value);')

View File

@ -0,0 +1 @@
[vlib/v/tests/inout/dump_none.vv:2] none: none

View File

@ -0,0 +1,3 @@
fn main() {
dump(none)
}