Skip to content

Commit

Permalink
checker: minor cleanup of fn_decl check (#19627)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Oct 23, 2023
1 parent 9982fa4 commit 65d7126
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -272,25 +272,25 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.error('duplicate of an import symbol `${param.name}`', param.pos)
}
}
// Check if function name is already registered as imported module symbol
if !node.is_method && c.check_import_sym_conflict(node.short_name) {
c.error('duplicate of an import symbol `${node.short_name}`', node.pos)
}
}
if node.language == .v && node.name.after_char(`.`) == 'init' && !node.is_method
&& node.params.len == 0 {
if node.is_pub {
c.error('fn `init` must not be public', node.pos)
}
if node.return_type != ast.void_type {
c.error('fn `init` cannot have a return type', node.pos)
if !node.is_method {
// Check if function name is already registered as imported module symbol
if c.check_import_sym_conflict(node.short_name) {
c.error('duplicate of an import symbol `${node.short_name}`', node.pos)
}
if node.params.len == 0 && node.name.after_char(`.`) == 'init' {
if node.is_pub {
c.error('fn `init` must not be public', node.pos)
}
if node.return_type != ast.void_type {
c.error('fn `init` cannot have a return type', node.pos)
}
}
if !c.is_builtin_mod && node.mod == 'main'
&& node.name.after_char(`.`) in reserved_type_names {
c.error('top level declaration cannot shadow builtin type', node.pos)
}
}
}

if node.language == .v && node.mod == 'main' && node.name.after_char(`.`) in reserved_type_names
&& !node.is_method && !c.is_builtin_mod {
c.error('top level declaration cannot shadow builtin type', node.pos)
}
if node.return_type != ast.Type(0) {
if !c.ensure_type_exists(node.return_type, node.return_type_pos) {
return
Expand Down

0 comments on commit 65d7126

Please sign in to comment.