From 2f4fc86d588ab4e92212921f6479ce05fadc59a4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 8 May 2020 15:00:04 +0200 Subject: [PATCH] checker: fix unknown var enum crash --- vlib/v/checker/checker.v | 7 +++++++ vlib/v/gen/cgen.v | 12 +++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 2a4cfe0c5c..cd1da1863c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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() diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index dbc7580757..8b331bb5c4 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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(',') }