You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expecting array operators to also work on enumerated arrays (i have a work around, but not sure if its ideal)
package main
import "core:fmt"
myEnum :: enum {
A,B,C
}
main :: proc() {
arrayA: [10]int
// expected
fmt.println(arrayA + 10)
arrayB: [myEnum]int
// fails to compile
fmt.println(arrayB + 10)
// workaround, but not sure if it has the same compiler advantages as above
fmt.println(arrayB + [myEnum]int{.A=10,.B=10,.C=10})
}
Current Behavior
Array operators work on normal array of numbers, but fails for enumerated array of numbers
Failure Information (for bugs)
I also found a related resolved issue #1042 so I'm assuming the semantics of array of numbers should carry forward to enumerated arrays of numbers.
Steps to Reproduce
try to compile
compilation error
Failure Logs
Error: Cannot convert untyped value '10' to '[myEnum]int' from 'untyped integer'
fmt.println(arrayB + 10)
^^
The text was updated successfully, but these errors were encountered:
hyperturtle
changed the title
Array operators on enumerated arrays or numbers
Array operators on enumerated arrays of numbers
Feb 13, 2025
Thanks for the reply! I'm really loving Odin so far, so I'll find a way for it to work for me. The reason I wanted to use enumerated arrays, is to be able to make sure I index into an array for only specific names. I know there's many ways I could've wrote this but here's what I had before I learned about enumerated arrays.
Being able to do array math on a vector has made the code easier to work with.
What I'm doing now
unit.resists[element.DARK] = 10
vs what would be possible with enumerated arrays (along with making sure I dont use other enums accidentally)
unit.resists[.COLD] = 10
If this example isn't convincing, feel free to close. I'll continue with the non-enumerated array version as I think it'll best suit what I need it to do
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
both windows and osx
dev-2025-01-nightly:2aae4cf
odin report
output:Expected Behavior
Expecting array operators to also work on enumerated arrays (i have a work around, but not sure if its ideal)
Current Behavior
Array operators work on normal array of numbers, but fails for enumerated array of numbers
Failure Information (for bugs)
I also found a related resolved issue #1042 so I'm assuming the semantics of array of numbers should carry forward to enumerated arrays of numbers.
Steps to Reproduce
Failure Logs
The text was updated successfully, but these errors were encountered: