Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent array mathematics for enumerated arrays #4268

Open
GriffonOak opened this issue Sep 18, 2024 · 0 comments
Open

Inconsistent array mathematics for enumerated arrays #4268

GriffonOak opened this issue Sep 18, 2024 · 0 comments

Comments

@GriffonOak
Copy link

Context

Odin:    dev-2024-09-nightly:dd1f151
OS:      Windows 11 Home Basic (version: 23H2), build 22631.4169
CPU:     AMD Ryzen 5 5600X 6-Core Processor
RAM:     32691 MiB
Backend: LLVM 18.1.8

The following code demonstrates the problem:

package main
import "core:fmt"

Enum :: enum { P, Q }

EnumArray :: [Enum]int

main :: proc() {
    a: EnumArray = {.P = 2, .Q = 3}
    b: EnumArray = {.P = 4, .Q = 5}

    fmt.println(a + b)      // prints [.P = 6, .Q = 8]
    fmt.println(a * b)      // prints [.P = 8, .Q = 15]
    fmt.println(a + 2 * b)  // does not compile

    // Workaround using transmute:
    fmt.println(a + transmute(EnumArray) (transmute([len(Enum)]int) b * 2))
    // prints [.P = 10, .Q = 13]
}

Expected Behavior

Scalar multiplication should work with enumerated arrays of numeric types exactly as it does with normal arrays of numeric types.

Current Behavior

Enumerated arrays support addition and multiplication between each other, but not multiplication by scalars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant