mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: disallow module name as expression name
This commit is contained in:
parent
134e781965
commit
3248962111
@ -202,6 +202,10 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
|||||||
match mut lx {
|
match mut lx {
|
||||||
ast.Ident {
|
ast.Ident {
|
||||||
if op == .decl_assign {
|
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) {
|
if p.scope.known_var(lx.name) {
|
||||||
return p.error_with_pos('redefinition of `${lx.name}`', lx.pos)
|
return p.error_with_pos('redefinition of `${lx.name}`', lx.pos)
|
||||||
}
|
}
|
||||||
|
@ -373,6 +373,12 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||||||
params << args2
|
params << args2
|
||||||
if !are_args_type_only {
|
if !are_args_type_only {
|
||||||
for k, param in params {
|
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) {
|
if p.scope.known_var(param.name) {
|
||||||
p.error_with_pos('redefinition of parameter `${param.name}`', param.pos)
|
p.error_with_pos('redefinition of parameter `${param.name}`', param.pos)
|
||||||
return ast.FnDecl{
|
return ast.FnDecl{
|
||||||
|
@ -3677,6 +3677,9 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
if p.tok.kind == .decl_assign {
|
if p.tok.kind == .decl_assign {
|
||||||
p.error_with_pos('cannot use `:=` to declare a const, use `=` instead', p.tok.pos())
|
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)
|
p.check(.assign)
|
||||||
end_comments << p.eat_comments()
|
end_comments << p.eat_comments()
|
||||||
if p.tok.kind == .key_fn {
|
if p.tok.kind == .key_fn {
|
||||||
|
Loading…
Reference in New Issue
Block a user