checker: fix Assoc
parent
85f67a3f73
commit
27ce38937c
|
@ -513,9 +513,10 @@ pub:
|
|||
|
||||
pub struct Assoc {
|
||||
pub:
|
||||
name string
|
||||
var_name string
|
||||
fields []string
|
||||
exprs []Expr
|
||||
pos token.Position
|
||||
}
|
||||
|
||||
pub struct SizeOf {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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: ')
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue