diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index 99a2c226b8..5174639ae1 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -202,6 +202,10 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme match mut lx { ast.Ident { if op == .decl_assign { + if p.mod == lx.name { + return p.error_with_pos('expression names cannot match module name', + lx.pos) + } if p.scope.known_var(lx.name) { return p.error_with_pos('redefinition of `${lx.name}`', lx.pos) } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 44fb613c99..1ebd822a5f 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -373,6 +373,12 @@ fn (mut p Parser) fn_decl() ast.FnDecl { params << args2 if !are_args_type_only { for k, param in params { + if p.mod == param.name { + p.error_with_pos('parameter names cannot match module name', param.pos) + return ast.FnDecl{ + scope: 0 + } + } if p.scope.known_var(param.name) { p.error_with_pos('redefinition of parameter `${param.name}`', param.pos) return ast.FnDecl{ diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 246d7230b6..63f2466c51 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3677,6 +3677,9 @@ fn (mut p Parser) const_decl() ast.ConstDecl { if p.tok.kind == .decl_assign { p.error_with_pos('cannot use `:=` to declare a const, use `=` instead', p.tok.pos()) } + if p.mod == name { + p.error_with_pos('const names cannot match module name', pos) + } p.check(.assign) end_comments << p.eat_comments() if p.tok.kind == .key_fn {