checker: prompt error on script expression while inside a file with main (#6400)
							parent
							
								
									4038ac463c
								
							
						
					
					
						commit
						c02a0f90df
					
				| 
						 | 
					@ -191,6 +191,9 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			ast.FnDecl {
 | 
								ast.FnDecl {
 | 
				
			||||||
				if stmt.name == 'main.main' {
 | 
									if stmt.name == 'main.main' {
 | 
				
			||||||
 | 
										if has_main_fn {
 | 
				
			||||||
 | 
											c.error('function `main` is already defined', stmt.pos)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
					has_main_fn = true
 | 
										has_main_fn = true
 | 
				
			||||||
					if stmt.is_pub {
 | 
										if stmt.is_pub {
 | 
				
			||||||
						c.error('function `main` cannot be declared public', stmt.pos)
 | 
											c.error('function `main` cannot be declared public', stmt.pos)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					vlib/v/checker/tests/main_and_script_err.vv:1:1: error: function `main` is already defined
 | 
				
			||||||
 | 
					    1 | fn main() {
 | 
				
			||||||
 | 
					      | ^
 | 
				
			||||||
 | 
					    2 |     println('main')
 | 
				
			||||||
 | 
					    3 | }
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						println('main')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					println('out')
 | 
				
			||||||
		Loading…
	
		Reference in New Issue