negative enum vals + `[10]C.Foo` fix
parent
faca61c50a
commit
31b7991a93
|
@ -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 {
|
||||
|
|
|
@ -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`')
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue