checker: fix appending an .enum_val to a struct field of []Enum
parent
f8b237433f
commit
5825e467b8
|
@ -2229,15 +2229,20 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) table.Type {
|
||||||
c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos)
|
c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos)
|
||||||
return table.void_type
|
return table.void_type
|
||||||
}
|
}
|
||||||
typ := table.new_type(typ_idx)
|
mut typ := table.new_type(typ_idx)
|
||||||
if typ == table.void_type {
|
if typ == table.void_type {
|
||||||
c.error('not an enum', node.pos)
|
c.error('not an enum', node.pos)
|
||||||
return table.void_type
|
return table.void_type
|
||||||
}
|
}
|
||||||
typ_sym := c.table.get_type_symbol(typ)
|
mut typ_sym := c.table.get_type_symbol(typ)
|
||||||
// println('tname=$typ_sym.name $node.pos.line_nr $c.file.path')
|
// println('tname=$typ_sym.name $node.pos.line_nr $c.file.path')
|
||||||
|
if typ_sym.kind == .array && node.enum_name.len == 0 {
|
||||||
|
array_info := typ_sym.info as table.Array
|
||||||
|
typ = array_info.elem_type
|
||||||
|
typ_sym = c.table.get_type_symbol(typ)
|
||||||
|
}
|
||||||
if typ_sym.kind != .enum_ {
|
if typ_sym.kind != .enum_ {
|
||||||
c.error('not an enum', node.pos)
|
c.error('expected type is not an enum', node.pos)
|
||||||
return table.void_type
|
return table.void_type
|
||||||
}
|
}
|
||||||
if !(typ_sym.info is table.Enum) {
|
if !(typ_sym.info is table.Enum) {
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
struct Abc {
|
||||||
|
mut:
|
||||||
|
flags []Flag
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Flag {
|
||||||
|
flag_one
|
||||||
|
flag_two
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_enum_array_field() {
|
||||||
|
mut a := Abc{}
|
||||||
|
a.flags << .flag_one
|
||||||
|
assert true
|
||||||
|
a.flags << .flag_two
|
||||||
|
assert true
|
||||||
|
a.flags << .flag_one
|
||||||
|
println(a)
|
||||||
|
assert true
|
||||||
|
}
|
Loading…
Reference in New Issue