mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix error msg for index error for int ptr (#18896)
This commit is contained in:
parent
4f629cd883
commit
e5a727c3e1
@ -4076,9 +4076,9 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty
|
|||||||
&& (index_type_sym.info as ast.Alias).parent_type.is_int())
|
&& (index_type_sym.info as ast.Alias).parent_type.is_int())
|
||||||
|| (c.pref.translated && index_type.is_any_kind_of_pointer())) {
|
|| (c.pref.translated && index_type.is_any_kind_of_pointer())) {
|
||||||
type_str := if typ_sym.kind == .string {
|
type_str := if typ_sym.kind == .string {
|
||||||
'non-integer string index `${index_type_sym.name}`'
|
'non-integer string index `${c.table.type_to_str(index_type)}`'
|
||||||
} else {
|
} else {
|
||||||
'non-integer index `${index_type_sym.name}` (array type `${typ_sym.name}`)'
|
'non-integer index `${c.table.type_to_str(index_type)}` (array type `${typ_sym.name}`)'
|
||||||
}
|
}
|
||||||
c.error('${type_str}', pos)
|
c.error('${type_str}', pos)
|
||||||
}
|
}
|
||||||
|
6
vlib/v/checker/tests/int_ptr_array_index_err.out
Normal file
6
vlib/v/checker/tests/int_ptr_array_index_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/int_ptr_array_index_err.vv:5:14: error: non-integer index `&int` (array type `[]u8`)
|
||||||
|
3 | offset += 4
|
||||||
|
4 | }
|
||||||
|
5 | return bytes[offset]
|
||||||
|
| ~~~~~~~~
|
||||||
|
6 | }
|
6
vlib/v/checker/tests/int_ptr_array_index_err.vv
Normal file
6
vlib/v/checker/tests/int_ptr_array_index_err.vv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pub fn read_int(bytes []u8, mut offset &int) int {
|
||||||
|
defer {
|
||||||
|
offset += 4
|
||||||
|
}
|
||||||
|
return bytes[offset]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user