File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module parser
66import v.ast
77import v.token
88import v.util
9+ import os
910
1011pub fn (mut p Parser) call_expr (language ast.Language, mod string ) ast.CallExpr {
1112 first_pos := p.tok.pos ()
@@ -399,6 +400,16 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
399400 is_test := (! is_method && params.len == 0 ) && p.inside_test_file
400401 && (short_fn_name.starts_with ('test_' ) || short_fn_name.starts_with ('testsuite_' ))
401402 file_mode := p.file_backend_mode
403+ if is_main {
404+ if _ := p.table.find_fn ('main.main' ) {
405+ if '.' in os.args {
406+ p.error_with_pos ('multiple `main` functions detected, and you ran `v .`
407+ perhaps there are multiple V programs in this directory, and you need to
408+ run them via `v file.v` instead' ,
409+ name_pos)
410+ }
411+ }
412+ }
402413 // Register
403414 if is_method {
404415 mut type_sym := p.table.sym (rec.typ)
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ module parser
66import v.ast
77import v.token
88import v.util
9- import os
109
1110fn (mut p Parser) struct_decl (is_anon bool ) ast.StructDecl {
1211 p.top_level_statement_start ()
@@ -361,15 +360,6 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
361360 }
362361 // allow duplicate c struct declarations
363362 if ret == - 1 && language != .c {
364- if _ := p.table.find_fn ('main.main' ) {
365- if '.' in os.args {
366- p.error_with_pos ('multiple `main` functions detected, and you ran `v .`
367- perhaps there are multiple V programs in this directory, and you need to
368- run them via `v file.v` instead' ,
369- name_pos)
370- return ast.StructDecl{}
371- }
372- }
373363 p.error_with_pos ('cannot register struct `$name `, another type with this name exists' ,
374364 name_pos)
375365 return ast.StructDecl{}
You can’t perform that action at this time.
0 commit comments