mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast, checker, parser: add enum type pos (#17112)
This commit is contained in:
parent
6bb930591e
commit
e32ed368ca
@ -1176,6 +1176,7 @@ pub:
|
||||
fields []EnumField // all the enum fields
|
||||
attrs []Attr // attributes of enum declaration
|
||||
typ Type // the default is `int`; can be changed by `enum Big as u64 { a = 5 }`
|
||||
typ_pos token.Pos
|
||||
pos token.Pos
|
||||
}
|
||||
|
||||
|
@ -1579,7 +1579,7 @@ fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
|
||||
}
|
||||
else {
|
||||
c.error('`${senum_type}` is not one of `i8`,`i16`,`int`,`i64`,`u8`,`u16`,`u32`,`u64`',
|
||||
node.pos)
|
||||
node.typ_pos)
|
||||
}
|
||||
}
|
||||
if enum_imin > 0 {
|
||||
|
@ -5,11 +5,11 @@ vlib/v/checker/tests/enum_field_value_overflow.vv:3:10: error: enum value `21474
|
||||
| ~~~~~~~~~~
|
||||
4 | blue
|
||||
5 | }
|
||||
vlib/v/checker/tests/enum_field_value_overflow.vv:7:1: error: `string` is not one of `i8`,`i16`,`int`,`i64`,`u8`,`u16`,`u32`,`u64`
|
||||
vlib/v/checker/tests/enum_field_value_overflow.vv:7:21: error: `string` is not one of `i8`,`i16`,`int`,`i64`,`u8`,`u16`,`u32`,`u64`
|
||||
5 | }
|
||||
6 |
|
||||
7 | enum ColorString as string {
|
||||
| ~~~~~~~~~~~~~~~~
|
||||
| ~~~~~~
|
||||
8 | red
|
||||
9 | green = 'abc'
|
||||
vlib/v/checker/tests/enum_field_value_overflow.vv:9:10: error: the default value for an enum has to be an integer
|
||||
|
@ -3774,8 +3774,10 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||
}
|
||||
name := p.prepend_mod(enum_name)
|
||||
mut enum_type := ast.int_type
|
||||
mut typ_pos := token.Pos{}
|
||||
if p.tok.kind == .key_as {
|
||||
p.next()
|
||||
typ_pos = p.tok.pos()
|
||||
enum_type = p.parse_type()
|
||||
}
|
||||
p.check(.lcbr)
|
||||
@ -3856,6 +3858,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||
enum_decl := ast.EnumDecl{
|
||||
name: name
|
||||
typ: enum_type
|
||||
typ_pos: typ_pos
|
||||
is_pub: is_pub
|
||||
is_flag: is_flag
|
||||
is_multi_allowed: is_multi_allowed
|
||||
|
Loading…
Reference in New Issue
Block a user