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

v2: fix var mistaken for enum in parser

This commit is contained in:
Joe Conigliaro 2020-03-02 01:19:10 +11:00
parent 82b0024758
commit 1ab830da4b
2 changed files with 15 additions and 13 deletions

View File

@ -785,7 +785,7 @@ pub fn (c mut Checker) enum_val(node ast.EnumVal) table.Type {
c.table.find_type_idx(node.enum_name) }
// println('checker: enum_val: $node.enum_name typeidx=$typ_idx')
if typ_idx == 0 {
c.error('not an enum (type_idx=0)', node.pos)
c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos)
}
typ := c.table.get_type_symbol(table.Type(typ_idx))
// println('tname=$typ.name')

View File

@ -641,7 +641,9 @@ pub fn (p mut Parser) name_expr() ast.Expr {
// || p.table.known_type(p.tok.lit)) {
return p.struct_init()
}
else if p.peek_tok.kind == .dot && p.tok.lit[0].is_capital() {
else if p.peek_tok.kind == .dot &&
//
(p.tok.lit[0].is_capital() && !p.scope.known_var(p.tok.lit)) {
// `Color.green`
mut enum_name := p.check_name()
if mod != '' {
@ -796,7 +798,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
var_name: name
fields: fields
exprs: vals
pos:p.tok.position()
pos: p.tok.position()
}
}
p.check(.rcbr)