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

compiler: use type unresolved for unresolved consts

This commit is contained in:
hazohelet 2020-03-30 02:26:55 +09:00 committed by GitHub
parent bf9f3057da
commit ec025f2020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -756,9 +756,9 @@ fn (p mut Parser) const_decl() {
if p.first_pass() {
p.table.register_const(name, typ, p.mod, is_pub)
}
// Check to see if this constant exists, and is void. If so, try and get the type again:
// Check to see if this constant exists, and is unresolved. If so, try and get the type again:
if my_const := p.v.table.find_const(name) {
if my_const.typ == 'void' {
if my_const.typ == 'unresolved' {
for i, v in p.v.table.consts {
if v.name == name {
p.v.table.consts[i].typ = typ

View File

@ -457,7 +457,7 @@ fn (p mut Parser) name_expr() string {
// First pass, the function can be defined later.
if p.first_pass() {
p.next()
return 'void'
return 'unresolved'
}
// exhaused all options type,enum,const,mod,var,fn etc
// so show undefined error (also checks typos)
@ -680,7 +680,7 @@ fn (p mut Parser) handle_operator(op string, typ string,cpostfix string, ph int,
p.cgen.set_placeholder(ph, '${typ}_${cpostfix}(')
p.gen(')')
}
else {
else if typ != 'unresolved' {
p.error('operator $op not defined on `$typ`')
}
}

View File

@ -2,6 +2,8 @@ pub const (
// c = a // TODO
a = b
b = 1
d = (e / 2) + 7
e = 9
)
struct Foo {
@ -10,5 +12,6 @@ struct Foo {
fn test_const() {
assert a == 1
assert d == 11
// assert c == 1 // TODO: This will not build yet
}