mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix checking for duplicate main functions (#15946)
This commit is contained in:
parent
ed2960a20e
commit
b158da398b
@ -6,6 +6,7 @@ module parser
|
|||||||
import v.ast
|
import v.ast
|
||||||
import v.token
|
import v.token
|
||||||
import v.util
|
import v.util
|
||||||
|
import os
|
||||||
|
|
||||||
pub fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr {
|
pub fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr {
|
||||||
first_pos := p.tok.pos()
|
first_pos := p.tok.pos()
|
||||||
@ -399,6 +400,16 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||||||
is_test := (!is_method && params.len == 0) && p.inside_test_file
|
is_test := (!is_method && params.len == 0) && p.inside_test_file
|
||||||
&& (short_fn_name.starts_with('test_') || short_fn_name.starts_with('testsuite_'))
|
&& (short_fn_name.starts_with('test_') || short_fn_name.starts_with('testsuite_'))
|
||||||
file_mode := p.file_backend_mode
|
file_mode := p.file_backend_mode
|
||||||
|
if is_main {
|
||||||
|
if _ := p.table.find_fn('main.main') {
|
||||||
|
if '.' in os.args {
|
||||||
|
p.error_with_pos('multiple `main` functions detected, and you ran `v .`
|
||||||
|
perhaps there are multiple V programs in this directory, and you need to
|
||||||
|
run them via `v file.v` instead',
|
||||||
|
name_pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Register
|
// Register
|
||||||
if is_method {
|
if is_method {
|
||||||
mut type_sym := p.table.sym(rec.typ)
|
mut type_sym := p.table.sym(rec.typ)
|
||||||
|
@ -6,7 +6,6 @@ module parser
|
|||||||
import v.ast
|
import v.ast
|
||||||
import v.token
|
import v.token
|
||||||
import v.util
|
import v.util
|
||||||
import os
|
|
||||||
|
|
||||||
fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
||||||
p.top_level_statement_start()
|
p.top_level_statement_start()
|
||||||
@ -361,15 +360,6 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
|||||||
}
|
}
|
||||||
// allow duplicate c struct declarations
|
// allow duplicate c struct declarations
|
||||||
if ret == -1 && language != .c {
|
if ret == -1 && language != .c {
|
||||||
if _ := p.table.find_fn('main.main') {
|
|
||||||
if '.' in os.args {
|
|
||||||
p.error_with_pos('multiple `main` functions detected, and you ran `v .`
|
|
||||||
perhaps there are multiple V programs in this directory, and you need to
|
|
||||||
run them via `v file.v` instead',
|
|
||||||
name_pos)
|
|
||||||
return ast.StructDecl{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p.error_with_pos('cannot register struct `$name`, another type with this name exists',
|
p.error_with_pos('cannot register struct `$name`, another type with this name exists',
|
||||||
name_pos)
|
name_pos)
|
||||||
return ast.StructDecl{}
|
return ast.StructDecl{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user