checker: fix unknown var enum crash

pull/4788/head
Alexander Medvednikov 2020-05-08 15:00:04 +02:00
parent dbb3c2a4cd
commit 2f4fc86d58
2 changed files with 12 additions and 7 deletions

View File

@ -2084,15 +2084,22 @@ pub fn (mut c Checker) enum_val(node mut ast.EnumVal) table.Type {
// println('checker: enum_val: $node.enum_name typeidx=$typ_idx')
if typ_idx == 0 {
c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos)
return table.void_type
}
typ := table.new_type(typ_idx)
if typ == table.void_type {
c.error('not an enum', node.pos)
return table.void_type
}
typ_sym := c.table.get_type_symbol(typ)
// println('tname=$typ_sym.name $node.pos.line_nr $c.file.path')
if typ_sym.kind != .enum_ {
c.error('not an enum', node.pos)
return table.void_type
}
if !(typ_sym.info is table.Enum) {
c.error('not an enum', node.pos)
return table.void_type
}
// info := typ_sym.info as table.Enum
info := typ_sym.enum_info()

View File

@ -2162,13 +2162,11 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
field_name := c_name(field.name)
inited_fields << field.name
g.write('\t.$field_name = ')
/*
if g.autofree && right_sym.kind in [.array, .string] {
g.write('/*clone1*/')
if g.gen_clone_assignment(field.expr, right_sym, true) {
}
}
*/
// if g.autofree && right_sym.kind in [.array, .string] {
// g.write('/*clone1*/')
// if g.gen_clone_assignment(field.expr, right_sym, true) {
// }
// }
g.expr_with_cast(field.expr, field.typ, field.expected_type)
g.writeln(',')
}