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
|
fields []EnumField // all the enum fields
|
||||||
attrs []Attr // attributes of enum declaration
|
attrs []Attr // attributes of enum declaration
|
||||||
typ Type // the default is `int`; can be changed by `enum Big as u64 { a = 5 }`
|
typ Type // the default is `int`; can be changed by `enum Big as u64 { a = 5 }`
|
||||||
|
typ_pos token.Pos
|
||||||
pos token.Pos
|
pos token.Pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1579,7 +1579,7 @@ fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c.error('`${senum_type}` is not one of `i8`,`i16`,`int`,`i64`,`u8`,`u16`,`u32`,`u64`',
|
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 {
|
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
|
4 | blue
|
||||||
5 | }
|
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 | }
|
5 | }
|
||||||
6 |
|
6 |
|
||||||
7 | enum ColorString as string {
|
7 | enum ColorString as string {
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~
|
||||||
8 | red
|
8 | red
|
||||||
9 | green = 'abc'
|
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
|
vlib/v/checker/tests/enum_field_value_overflow.vv:9:10: error: the default value for an enum has to be an integer
|
||||||
@ -69,21 +69,21 @@ vlib/v/checker/tests/enum_field_value_overflow.vv:56:10: error: enum value `256`
|
|||||||
57 | }
|
57 | }
|
||||||
58 |
|
58 |
|
||||||
vlib/v/checker/tests/enum_field_value_overflow.vv:60:10: error: enum value `65536` overflows the enum type `u16`, values of which have to be in [0, 65535]
|
vlib/v/checker/tests/enum_field_value_overflow.vv:60:10: error: enum value `65536` overflows the enum type `u16`, values of which have to be in [0, 65535]
|
||||||
58 |
|
58 |
|
||||||
59 | enum ColorU16ShouldFail as u16 {
|
59 | enum ColorU16ShouldFail as u16 {
|
||||||
60 | green = 65536
|
60 | green = 65536
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
61 | }
|
61 | }
|
||||||
62 |
|
62 |
|
||||||
vlib/v/checker/tests/enum_field_value_overflow.vv:64:10: error: enum value `4294967296` overflows the enum type `u32`, values of which have to be in [0, 4294967295]
|
vlib/v/checker/tests/enum_field_value_overflow.vv:64:10: error: enum value `4294967296` overflows the enum type `u32`, values of which have to be in [0, 4294967295]
|
||||||
62 |
|
62 |
|
||||||
63 | enum ColorU32ShouldFail as u32 {
|
63 | enum ColorU32ShouldFail as u32 {
|
||||||
64 | green = 4294967296
|
64 | green = 4294967296
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
65 | }
|
65 | }
|
||||||
66 |
|
66 |
|
||||||
vlib/v/checker/tests/enum_field_value_overflow.vv:68:10: error: enum value `18446744073709551616` overflows the enum type `u64`, values of which have to be in [0, 18446744073709551615]
|
vlib/v/checker/tests/enum_field_value_overflow.vv:68:10: error: enum value `18446744073709551616` overflows the enum type `u64`, values of which have to be in [0, 18446744073709551615]
|
||||||
66 |
|
66 |
|
||||||
67 | enum ColorU64ShouldFail as u64 {
|
67 | enum ColorU64ShouldFail as u64 {
|
||||||
68 | green = 18446744073709551616
|
68 | green = 18446744073709551616
|
||||||
| ~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -3774,8 +3774,10 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
|||||||
}
|
}
|
||||||
name := p.prepend_mod(enum_name)
|
name := p.prepend_mod(enum_name)
|
||||||
mut enum_type := ast.int_type
|
mut enum_type := ast.int_type
|
||||||
|
mut typ_pos := token.Pos{}
|
||||||
if p.tok.kind == .key_as {
|
if p.tok.kind == .key_as {
|
||||||
p.next()
|
p.next()
|
||||||
|
typ_pos = p.tok.pos()
|
||||||
enum_type = p.parse_type()
|
enum_type = p.parse_type()
|
||||||
}
|
}
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
@ -3856,6 +3858,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
|||||||
enum_decl := ast.EnumDecl{
|
enum_decl := ast.EnumDecl{
|
||||||
name: name
|
name: name
|
||||||
typ: enum_type
|
typ: enum_type
|
||||||
|
typ_pos: typ_pos
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
is_flag: is_flag
|
is_flag: is_flag
|
||||||
is_multi_allowed: is_multi_allowed
|
is_multi_allowed: is_multi_allowed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user