v2: fix var mistaken for enum in parser

pull/3907/head
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) } c.table.find_type_idx(node.enum_name) }
// println('checker: enum_val: $node.enum_name typeidx=$typ_idx') // println('checker: enum_val: $node.enum_name typeidx=$typ_idx')
if typ_idx == 0 { 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)) typ := c.table.get_type_symbol(table.Type(typ_idx))
// println('tname=$typ.name') // println('tname=$typ.name')

View File

@ -58,7 +58,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
pref: &pref.Preferences{} pref: &pref.Preferences{}
scope: scope scope: scope
// scope: &ast.Scope{start_pos: 0, parent: 0} // scope: &ast.Scope{start_pos: 0, parent: 0}
} }
p.init_parse_fns() p.init_parse_fns()
p.read_first_token() p.read_first_token()
@ -82,7 +82,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
parent: 0 parent: 0
} }
// comments_mode: comments_mode // comments_mode: comments_mode
} }
p.read_first_token() p.read_first_token()
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0} // p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
@ -359,7 +359,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
return ast.ExprStmt{ return ast.ExprStmt{
expr: expr expr: expr
// typ: typ // typ: typ
} }
} }
} }
@ -641,7 +641,9 @@ pub fn (p mut Parser) name_expr() ast.Expr {
// || p.table.known_type(p.tok.lit)) { // || p.table.known_type(p.tok.lit)) {
return p.struct_init() 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` // `Color.green`
mut enum_name := p.check_name() mut enum_name := p.check_name()
if mod != '' { if mod != '' {
@ -657,7 +659,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
p.expr_mod = '' p.expr_mod = ''
return ast.EnumVal{ return ast.EnumVal{
enum_name: enum_name // lp.prepend_mod(enum_name) enum_name: enum_name // lp.prepend_mod(enum_name)
val: val val: val
pos: p.tok.position() pos: p.tok.position()
} }
@ -796,7 +798,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
var_name: name var_name: name
fields: fields fields: fields
exprs: vals exprs: vals
pos:p.tok.position() pos: p.tok.position()
} }
} }
p.check(.rcbr) p.check(.rcbr)
@ -1215,11 +1217,11 @@ fn (p mut Parser) if_expr() ast.Expr {
stmts: stmts stmts: stmts
else_stmts: else_stmts else_stmts: else_stmts
// typ: typ // typ: typ
pos: pos pos: pos
has_else: has_else has_else: has_else
// left: left // left: left
} }
return node return node
} }
@ -1645,12 +1647,12 @@ fn (p mut Parser) var_decl_and_assign_stmt() ast.Stmt {
return ast.VarDecl{ return ast.VarDecl{
name: ident.name name: ident.name
// name2: name2 // name2: name2
expr: expr // p.expr(token.lowest_prec) expr: expr // p.expr(token.lowest_prec)
is_mut: info0.is_mut is_mut: info0.is_mut
// typ: typ // typ: typ
pos: p.tok.position() pos: p.tok.position()
} }
// return p.var_decl(ident[0], exprs[0]) // return p.var_decl(ident[0], exprs[0])
@ -1788,7 +1790,7 @@ fn (p mut Parser) match_expr() ast.Expr {
blocks: blocks blocks: blocks
match_exprs: match_exprs match_exprs: match_exprs
// typ: typ // typ: typ
cond: cond cond: cond
} }
return node return node