1
0
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:
yuyi 2022-10-02 17:14:25 +08:00 committed by GitHub
parent ed2960a20e
commit b158da398b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -6,6 +6,7 @@ module parser
import v.ast
import v.token
import v.util
import os
pub fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr {
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
&& (short_fn_name.starts_with('test_') || short_fn_name.starts_with('testsuite_'))
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
if is_method {
mut type_sym := p.table.sym(rec.typ)

View File

@ -6,7 +6,6 @@ module parser
import v.ast
import v.token
import v.util
import os
fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
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
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',
name_pos)
return ast.StructDecl{}