mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: allow enum value to be used as int
This commit is contained in:
parent
f57a651e3b
commit
16528b12fa
@ -764,8 +764,10 @@ pub fn (c mut Checker) index_expr(node ast.IndexExpr) table.Type {
|
||||
if !is_range {
|
||||
typ_sym := c.table.get_type_symbol(typ)
|
||||
index_type := c.expr(node.index)
|
||||
index_type_sym := c.table.get_type_symbol(index_type)
|
||||
// println('index expr left=$typ_sym.name $node.pos.line_nr')
|
||||
if typ_sym.kind == .array && !(table.type_idx(index_type) in table.number_idxs) {
|
||||
if typ_sym.kind == .array &&
|
||||
(!(table.type_idx(index_type) in table.number_idxs) && index_type_sym.kind != .enum_) {
|
||||
c.error('non-integer index (type `$typ_sym.name`)', node.pos)
|
||||
}
|
||||
else if typ_sym.kind == .map && table.type_idx(index_type) != table.string_type_idx {
|
||||
|
@ -386,6 +386,11 @@ pub fn (t &Table) check(got, expected Type) bool {
|
||||
if got_type_sym.is_int() && exp_type_sym.is_int() {
|
||||
return true
|
||||
}
|
||||
// allow enum value to be used as int
|
||||
if (got_type_sym.is_int() && exp_type_sym.kind == .enum_) ||
|
||||
(exp_type_sym.is_int() && got_type_sym.kind == .enum_) {
|
||||
return true
|
||||
}
|
||||
// TODO
|
||||
if got_type_sym.is_number() && exp_type_sym.is_number() {
|
||||
return true
|
||||
|
Loading…
Reference in New Issue
Block a user