parent
							
								
									6f5c1f060c
								
							
						
					
					
						commit
						7b9756be72
					
				|  | @ -229,10 +229,12 @@ fn (mut p Parser) fn_decl() ast.FnDecl { | |||
| 	} | ||||
| 	mut name := '' | ||||
| 	if p.tok.kind == .name { | ||||
| 		pos := p.tok.position() | ||||
| 		// TODO high order fn
 | ||||
| 		name = if language == .js { p.check_js_name() } else { p.check_name() } | ||||
| 		if language == .v && !p.pref.translated && util.contains_capital(name) && p.mod != 'builtin' { | ||||
| 			p.error('function names cannot contain uppercase letters, use snake_case instead') | ||||
| 			p.error_with_pos('function names cannot contain uppercase letters, use snake_case instead', | ||||
| 				pos) | ||||
| 			return ast.FnDecl{ | ||||
| 				scope: 0 | ||||
| 			} | ||||
|  | @ -240,7 +242,14 @@ fn (mut p Parser) fn_decl() ast.FnDecl { | |||
| 		type_sym := p.table.get_type_symbol(rec_type) | ||||
| 		// interfaces are handled in the checker, methods can not be defined on them this way
 | ||||
| 		if is_method && (type_sym.has_method(name) && type_sym.kind != .interface_) { | ||||
| 			p.error('duplicate method `$name`') | ||||
| 			p.error_with_pos('duplicate method `$name`', pos) | ||||
| 			return ast.FnDecl{ | ||||
| 				scope: 0 | ||||
| 			} | ||||
| 		} | ||||
| 		// cannot redefine buildin function
 | ||||
| 		if !is_method && p.mod != 'builtin' && name in builtin_functions { | ||||
| 			p.error_with_pos('cannot redefine builtin function `$name`', pos) | ||||
| 			return ast.FnDecl{ | ||||
| 				scope: 0 | ||||
| 			} | ||||
|  |  | |||
|  | @ -14,6 +14,10 @@ import os | |||
| import runtime | ||||
| import time | ||||
| 
 | ||||
| const ( | ||||
| 	builtin_functions = ['print', 'println', 'eprint', 'eprintln', 'isnil', 'panic', 'exit'] | ||||
| ) | ||||
| 
 | ||||
| pub struct Parser { | ||||
| 	pref              &pref.Preferences | ||||
| mut: | ||||
|  |  | |||
|  | @ -0,0 +1,5 @@ | |||
| vlib/v/parser/tests/fn_use_builtin_err.vv:1:4: error: cannot redefine builtin function `print` | ||||
|     1 | fn print(strings ...string) { | ||||
|       |    ~~~~~ | ||||
|     2 |     for s in strings { | ||||
|     3 |         println(s) | ||||
|  | @ -0,0 +1,9 @@ | |||
| fn print(strings ...string) { | ||||
| 	for s in strings { | ||||
| 		println(s) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| fn main() { | ||||
| 	print('text') | ||||
| } | ||||
		Loading…
	
		Reference in New Issue