1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Felipe Pena 2023-06-25 16:10:50 -03:00
parent 100f441e3f
commit b00c8047e7
2 changed files with 10 additions and 3 deletions

View File

@ -553,6 +553,9 @@ fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) {
if ret_sym.kind == .placeholder { if ret_sym.kind == .placeholder {
c.error('unknown type `${ret_sym.name}`', fn_info.return_type_pos) c.error('unknown type `${ret_sym.name}`', fn_info.return_type_pos)
} }
if !node.typ.has_flag(.option) {
c.warn('you should declare it as Option instead', node.type_pos)
}
for arg in fn_info.params { for arg in fn_info.params {
c.ensure_type_exists(arg.typ, arg.type_pos) or { return } c.ensure_type_exists(arg.typ, arg.type_pos) or { return }
arg_sym := c.table.sym(arg.typ) arg_sym := c.table.sym(arg.typ)

View File

@ -137,9 +137,13 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
} }
if sym.kind == .function { if sym.kind == .function {
fn_info := sym.info as ast.FnType fn_info := sym.info as ast.FnType
if !field.typ.has_flag(.option) && fn_info.is_anon { if !field.typ.has_flag(.option) {
c.warn('direct function declaration is not recommended, use Option instead (?fn ...)', if fn_info.is_anon {
field.type_pos) c.warn('you should declare it as Option instead (?fn ...)', field.type_pos)
} else {
c.warn('this is not recommended, you should use Option function instead',
field.type_pos)
}
} }
} }