builder: fix detecting duplicate functions (#9033)
							parent
							
								
									6d77594409
								
							
						
					
					
						commit
						dc04c3196b
					
				|  | @ -366,7 +366,7 @@ fn (b &Builder) print_warnings_and_errors() { | |||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			if redefine_conflicts.len > 1 { | ||||
| 			if redefines.len > 0 { | ||||
| 				eprintln('redefinition of function `$fn_name`') | ||||
| 				for redefine in redefines { | ||||
| 					eprintln(util.formatted_error('conflicting declaration:', redefine.fheader, | ||||
|  |  | |||
|  | @ -0,0 +1,13 @@ | |||
| redefinition of function `main.f` | ||||
| vlib/v/checker/tests/fn_duplicate.vv:1:1: conflicting declaration: fn f() | ||||
|     1 | fn f() { | ||||
|       | ~~~~~~ | ||||
|     2 |      | ||||
|     3 | } | ||||
| vlib/v/checker/tests/fn_duplicate.vv:5:1: conflicting declaration: fn f(i int) | ||||
|     3 | } | ||||
|     4 |  | ||||
|     5 | fn f(i int) { | ||||
|       | ~~~~~~~~~~~ | ||||
|     6 |      | ||||
|     7 | } | ||||
|  | @ -0,0 +1,7 @@ | |||
| fn f() { | ||||
| 	 | ||||
| } | ||||
| 
 | ||||
| fn f(i int) { | ||||
| 	 | ||||
| } | ||||
|  | @ -329,8 +329,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl { | |||
| 		} else { | ||||
| 			name = p.prepend_mod(name) | ||||
| 		} | ||||
| 		if _ := p.table.find_fn(name) { | ||||
| 			p.fn_redefinition_error(name) | ||||
| 		if !p.pref.translated && language == .v && name in p.table.fns { | ||||
| 			p.table.redefined_fns << name | ||||
| 		} | ||||
| 		// p.warn('reg functn $name ()')
 | ||||
| 		p.table.register_fn(table.Fn{ | ||||
|  | @ -809,21 +809,6 @@ fn (mut p Parser) check_fn_atomic_arguments(typ table.Type, pos token.Position) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| fn (mut p Parser) fn_redefinition_error(name string) { | ||||
| 	if p.pref.translated { | ||||
| 		return | ||||
| 	} | ||||
| 	// Find where this function was already declared
 | ||||
| 	// TODO
 | ||||
| 	/* | ||||
| 	for file in p.ast_files { | ||||
| 
 | ||||
| 	} | ||||
| 	*/ | ||||
| 	p.table.redefined_fns << name | ||||
| 	// p.error('redefinition of function `$name`')
 | ||||
| } | ||||
| 
 | ||||
| fn have_fn_main(stmts []ast.Stmt) bool { | ||||
| 	for stmt in stmts { | ||||
| 		if stmt is ast.FnDecl { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue