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

all: minor cleanup of optional and result (#16382)

This commit is contained in:
yuyi 2022-11-11 02:14:20 +08:00 committed by GitHub
parent 26d643fc5d
commit 196b01aef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -282,6 +282,9 @@ pub fn (t Type) debug() []string {
if t.has_flag(.optional) {
res << 'optional'
}
if t.has_flag(.result) {
res << 'result'
}
if t.has_flag(.variadic) {
res << 'variadic'
}

View File

@ -32,7 +32,7 @@ pub fn (mut c Checker) get_default_fmt(ftyp ast.Type, typ ast.Type) u8 {
}
if ftyp in [ast.string_type, ast.bool_type]
|| sym.kind in [.enum_, .array, .array_fixed, .struct_, .map, .multi_return, .sum_type, .interface_, .none_]
|| ftyp.has_flag(.optional) || sym.has_method('str') {
|| ftyp.has_flag(.optional) || ftyp.has_flag(.result) || sym.has_method('str') {
return `s`
} else {
return `_`

View File

@ -67,6 +67,9 @@ fn (mut g Gen) get_str_fn(typ ast.Type) string {
if typ.has_flag(.optional) {
unwrapped.set_flag(.optional)
}
if typ.has_flag(.result) {
unwrapped.set_flag(.result)
}
styp := g.typ(unwrapped)
mut sym := g.table.sym(unwrapped)
mut str_fn_name := styp_to_str_fn_name(styp)