mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
const declarations should be order independent
This commit is contained in:
parent
2829298de7
commit
dfc654f84e
@ -534,6 +534,21 @@ fn (p mut Parser) const_decl() {
|
|||||||
if p.first_pass() {
|
if p.first_pass() {
|
||||||
p.table.register_const(name, typ, p.mod)
|
p.table.register_const(name, typ, p.mod)
|
||||||
}
|
}
|
||||||
|
// Check to see if this constant exists, and is void. If so, try and get the type again:
|
||||||
|
for { // TODO: Find out how the error handling, and use it here instead of the for/break hack...
|
||||||
|
my_const := p.v.table.find_const(name) or {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if my_const.typ == 'void' {
|
||||||
|
for i, v in p.v.table.consts {
|
||||||
|
if v.name == name {
|
||||||
|
p.v.table.consts[i].typ = typ
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
if p.pass == .main && !p.cgen.nogen {
|
if p.pass == .main && !p.cgen.nogen {
|
||||||
// TODO hack
|
// TODO hack
|
||||||
// cur_line has const's value right now. if it's just a number, then optimize generation:
|
// cur_line has const's value right now. if it's just a number, then optimize generation:
|
||||||
|
10
vlib/compiler/tests/const_test.v
Normal file
10
vlib/compiler/tests/const_test.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const (
|
||||||
|
// c = a // TODO
|
||||||
|
a = b
|
||||||
|
b = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
fn test_const() {
|
||||||
|
assert a == 1
|
||||||
|
// assert c == 1 // TODO: This will not build yet
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user