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 { | 		if p.tok == .assign { | ||||||
| 			p.fspace() | 			p.fspace() | ||||||
| 			mut enum_assign_tidx := p.cur_tok_index() | 			mut enum_assign_tidx := p.cur_tok_index() | ||||||
| 			if p.peek() == .number { | 			next := p.peek() | ||||||
|  | 			if next in [.number, .minus] { | ||||||
| 				p.next() | 				p.next() | ||||||
| 				p.fspace() | 				p.fspace() | ||||||
|  | 				is_neg := p.tok == .minus | ||||||
|  | 				if is_neg { | ||||||
|  | 					p.next() | ||||||
|  | 				} | ||||||
| 				val = p.lit.int() | 				val = p.lit.int() | ||||||
|  | 				if is_neg { | ||||||
|  | 					val = -val | ||||||
|  | 				} | ||||||
| 				p.next() | 				p.next() | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
|  |  | ||||||
|  | @ -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().col + p.peek_token().lit.len == p.peek_token().col {
 | ||||||
| 				if p.cur_tok().pos + p.peek_token().lit.len == p.peek_token().pos { | 				if p.cur_tok().pos + p.peek_token().lit.len == p.peek_token().pos { | ||||||
| 					p.check(.rsbr) | 					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() | 					array_elem_typ := p.get_type() | ||||||
| 					if !p.table.known_type(array_elem_typ) { | 					if !p.table.known_type(array_elem_typ) { | ||||||
| 						p.error('bad type `$array_elem_typ`') | 						p.error('bad type `$array_elem_typ`') | ||||||
|  |  | ||||||
|  | @ -39,3 +39,18 @@ fn test_match() { | ||||||
| 	println(color) | 	println(color) | ||||||
| 	assert num == 3 | 	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