1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: fix redefinition error message for consts

This commit is contained in:
hazohelet 2020-03-08 23:40:07 +09:00 committed by GitHub
parent 514b94ac69
commit ee6f2f84bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -720,12 +720,16 @@ fn (p mut Parser) const_decl() {
// }
continue
}
var_token_idx := p.cur_tok_index()
mut name := p.check_name() // `Age = 20`
// if !p.pref.building_v && p.mod != 'os' && contains_capital(name) {
// p.warn('const names cannot contain uppercase letters, use snake_case instead')
// }
name = p.prepend_mod(name)
mut typ := ''
if p.first_pass() && p.table.known_const(name) {
p.error_with_token_index('redefinition of `$name`', var_token_idx)
}
if p.is_vh {
// println('CONST VH $p.file_path')
// .vh files may not have const values, just types: `const (a int)`
@ -749,9 +753,6 @@ fn (p mut Parser) const_decl() {
p.check_space(.assign)
typ = p.expression()
}
if p.first_pass() && p.table.known_const(name) {
p.error('redefinition of `$name`')
}
if p.first_pass() {
p.table.register_const(name, typ, p.mod, is_pub)
}