checker: fix Assoc

pull/3884/head
Alexander Medvednikov 2020-02-29 18:07:29 +01:00
parent 85f67a3f73
commit 27ce38937c
5 changed files with 26 additions and 16 deletions

View File

@ -513,9 +513,10 @@ pub:
pub struct Assoc {
pub:
name string
var_name string
fields []string
exprs []Expr
pos token.Position
}
pub struct SizeOf {

View File

@ -431,6 +431,15 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
ast.AssignExpr {
c.check_assign_expr(it)
}
ast.Assoc {
scope := c.file.scope.innermost(it.pos.pos) or {
c.file.scope
}
var := scope.find_var(it.var_name) or {
panic(err)
}
return var.typ
}
ast.EnumVal {
return c.enum_val(it)
}
@ -733,8 +742,7 @@ pub fn (c mut Checker) enum_val(node ast.EnumVal) table.Type {
typ_idx := if node.enum_name == '' { c.expected_type } else { //
c.table.find_type_idx(node.enum_name) }
typ := c.table.get_type_symbol(table.Type(typ_idx))
//info := typ.info as table.Enum
// info := typ.info as table.Enum
info := typ.enum_info()
// rintln('checker: x = $info.x enum val $c.expected_type $typ.name')
// println(info.vals)

View File

@ -310,7 +310,7 @@ fn (f mut Fmt) expr(node ast.Expr) {
ast.Assoc {
f.writeln('{')
// f.indent++
f.writeln('\t$it.name |')
f.writeln('\t$it.var_name |')
// TODO StructInit copy pasta
for i, field in it.fields {
f.write('\t$field: ')

View File

@ -793,9 +793,10 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
}
}
node = ast.Assoc{
name: name
var_name: name
fields: fields
exprs: vals
pos:p.tok.position()
}
}
p.check(.rcbr)

View File

@ -76,7 +76,7 @@ x := 10
8+4
'
table := &table.Table{}
prog := parse_file(s, table)
prog := parse_file(s, table, .skip_comments)
mut checker := checker.new_checker(table)
checker.check(prog)
res := gen.cgen([prog], table)