Describe the bug
When trying to access an array, you're able to use a &int as an index by creating a new &int that equals your old &int value. This doesn't usually work as the compiler prevents &int's from being used as an index
pub fn read_int(bytes []u8, mut offset &int) int {
defer {
offset += 4
}
offset_d := offset
return bytes[offset_d] | ( int(bytes[offset_d+ 1]) << 8 ) | ( int(bytes[offset_d+ 2]) << 16 ) | ( int(bytes[offset_d + 3]) << 24 )
}
Expected Behavior
error: non-integer index int
Current Behavior
Instead, it returns the value stored at that index.
Reproduction Steps
pub fn read_int(bytes []u8, mut offset &int) int {
defer {
offset += 4
}
offset_d := offset
return bytes[offset_d] | ( int(bytes[offset_d+ 1]) << 8 ) | ( int(bytes[offset_d+ 2]) << 16 ) | ( int(bytes[offset_d + 3]) << 24 )
}
The above code results in zero errors, while the below code gives an error.
pub fn read_int(bytes []u8, mut offset &int) int {
defer {
offset += 4
}
return bytes[offset] | ( int(bytes[offset + 1]) << 8 ) | ( int(bytes[offset + 2]) << 16 ) | ( int(bytes[offset + 3]) << 24 ) // error: non-integer index `int`
}
reader/file_reader.v:6:14: error: non-integer index `int` (array type `[]u8`)
4 |
5 |
6 | return bytes[offset] | ( int(bytes[offset + 1]) << 8 ) | ( int(bytes[offset + 2]) << 16 ) | ( int(bytes[offset + 3]) << 24 )
| ~~~~~~~~
7 | }
8 |
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 130f35c.5e48817
Environment details (OS name and version, etc.)
windows, Microsoft Windows 11 Home v22621 64-bit
Describe the bug
When trying to access an array, you're able to use a &int as an index by creating a new &int that equals your old &int value. This doesn't usually work as the compiler prevents &int's from being used as an index
Expected Behavior
error: non-integer index
intCurrent Behavior
Instead, it returns the value stored at that index.
Reproduction Steps
The above code results in zero errors, while the below code gives an error.
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 130f35c.5e48817
Environment details (OS name and version, etc.)
windows, Microsoft Windows 11 Home v22621 64-bit