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-08-08 16:13:14 +02:00 committed by GitHub
commit 520a86dc95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -564,6 +564,9 @@ fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) {
if ret_sym.kind == .placeholder {
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 {
if !c.ensure_type_exists(arg.typ, arg.type_pos) {
return

View File

@ -152,6 +152,17 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
c.error('cannot use Result type as map value type', field.type_pos)
}
}
if sym.kind == .function {
fn_info := sym.info as ast.FnType
if !field.typ.has_flag(.option) {
if fn_info.is_anon {
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)
}
}
}
if field.has_default_expr {
c.expected_type = field.typ