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:
parent
514b94ac69
commit
ee6f2f84bb
@ -720,12 +720,16 @@ fn (p mut Parser) const_decl() {
|
|||||||
// }
|
// }
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
var_token_idx := p.cur_tok_index()
|
||||||
mut name := p.check_name() // `Age = 20`
|
mut name := p.check_name() // `Age = 20`
|
||||||
// if !p.pref.building_v && p.mod != 'os' && contains_capital(name) {
|
// if !p.pref.building_v && p.mod != 'os' && contains_capital(name) {
|
||||||
// p.warn('const names cannot contain uppercase letters, use snake_case instead')
|
// p.warn('const names cannot contain uppercase letters, use snake_case instead')
|
||||||
// }
|
// }
|
||||||
name = p.prepend_mod(name)
|
name = p.prepend_mod(name)
|
||||||
mut typ := ''
|
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 {
|
if p.is_vh {
|
||||||
// println('CONST VH $p.file_path')
|
// println('CONST VH $p.file_path')
|
||||||
// .vh files may not have const values, just types: `const (a int)`
|
// .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)
|
p.check_space(.assign)
|
||||||
typ = p.expression()
|
typ = p.expression()
|
||||||
}
|
}
|
||||||
if p.first_pass() && p.table.known_const(name) {
|
|
||||||
p.error('redefinition of `$name`')
|
|
||||||
}
|
|
||||||
if p.first_pass() {
|
if p.first_pass() {
|
||||||
p.table.register_const(name, typ, p.mod, is_pub)
|
p.table.register_const(name, typ, p.mod, is_pub)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user