diff --git a/vlib/compiler/enum.v b/vlib/compiler/enum.v index 317397f377..cdae97f573 100644 --- a/vlib/compiler/enum.v +++ b/vlib/compiler/enum.v @@ -39,10 +39,18 @@ fn (p mut Parser) enum_decl(no_name bool) { if p.tok == .assign { p.fspace() mut enum_assign_tidx := p.cur_tok_index() - if p.peek() == .number { + next := p.peek() + if next in [.number, .minus] { p.next() p.fspace() + is_neg := p.tok == .minus + if is_neg { + p.next() + } val = p.lit.int() + if is_neg { + val = -val + } p.next() } else { diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index b30063fc5c..1ab35f3f60 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -980,7 +980,7 @@ fn (p mut Parser) get_type() string { // Register anon fn type fn_typ := Type{ name: f.typ_str() // 'fn (int, int) string' - + mod: p.mod func: f } @@ -2534,6 +2534,11 @@ fn (p mut Parser) array_init() string { // if p.cur_tok().col + p.peek_token().lit.len == p.peek_token().col { if p.cur_tok().pos + p.peek_token().lit.len == p.peek_token().pos { p.check(.rsbr) + // `[10]C.kevent` needs `struct ` + is_c := p.tok == .name && p.lit == 'C' + if is_c { + p.cgen.insert_before('struct ') + } array_elem_typ := p.get_type() if !p.table.known_type(array_elem_typ) { p.error('bad type `$array_elem_typ`') diff --git a/vlib/compiler/tests/enum_test.v b/vlib/compiler/tests/enum_test.v index 45f14e3026..7c491028dd 100644 --- a/vlib/compiler/tests/enum_test.v +++ b/vlib/compiler/tests/enum_test.v @@ -39,3 +39,18 @@ fn test_match() { println(color) assert num == 3 } + +enum Foo { + a = 1 + b = 2 + c = 3 + d = -10 +} + +fn test_nums() { + foo := Foo.a + assert foo == 1 + assert Foo.c == 3 + d := Foo.d + assert d == -10 +}