diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index 3553cba664..1e9cd936d1 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -355,6 +355,9 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { c.warn('duplicate of a const name `${full_name}`', left.pos) } } + if left.mod == left.name && !c.file.path.contains('vlib') { + c.error('duplicate of an module name `${left.name}`', left.pos) + } // Check if variable name is already registered as imported module symbol if c.check_import_sym_conflict(left.name) { c.error('duplicate of an import symbol `${left.name}`', left.pos) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 1780668ec3..4593de5c44 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -256,11 +256,17 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } } } + if node.mod == param.name && !c.file.path.contains('vlib') { + c.error('duplicate of an module name `${param.name}`', param.pos) + } // Check if parameter name is already registered as imported module symbol if c.check_import_sym_conflict(param.name) { c.error('duplicate of an import symbol `${param.name}`', param.pos) } } + if node.mod == node.short_name && !c.file.path.contains('vlib') && node.mod != 'main' { + c.error('duplicate of an module name `${node.short_name}`', node.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)