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

Compiler bug with generics/poly and enumerated array constants. #4079

Closed
Chamberlain91 opened this issue Aug 14, 2024 · 0 comments
Closed

Compiler bug with generics/poly and enumerated array constants. #4079

Chamberlain91 opened this issue Aug 14, 2024 · 0 comments
Labels

Comments

@Chamberlain91
Copy link

Context

I was attempting to use enumerated arrays to map a constant of one to another value. It works for declaring a value on the stack, but making a poly procedure for it fails. With a little more of an elaborate example, its possible to get the compiler to output Internal Compiler Error: match_exact_values: How'd you get here? Invalid ExactValueKind 8.

Odin: dev-2024-08:3847d0324
OS: Windows 11 Home Basic (version: 24H2), build 26200.5001
CPU: AMD Ryzen 7 5700X 8-Core Processor
RAM: 32689 MiB
Backend: LLVM 18.1.8

Expected Behavior

Either for it to fully function in all cases, or to gracefully reject.

Current Behavior

It is inconsistent, or crashes the compiler depending on usage.

Failure Information (for bugs)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

package bug

import "core:fmt"

Dimension :: enum {
    D1,
    D2,
    D3,
}

when #config(BROKEN, false) {

    @(private)
    DIMENSION_COUNT :: [Dimension]int {
        .D1 = 1,
        .D2 = 2,
        .D3 = 3,
    }

    // Breaks when the function exists
    Image :: struct($DIM: Dimension) {
        size: [DIMENSION_COUNT[DIM]]int,
    }

} else {

    // Works with and without the function existing.
    Image :: struct($DIM: Dimension) {
        size: [1 + (u32)(DIM)]int,
    }

}

create_image :: proc($DIM: Dimension) -> Image(DIM) {
    image: Image(DIM)
    return image
}

main :: proc() {

    image1: Image(.D1)
    fmt.println(image1)

    image3 := create_image(.D3)
    fmt.println(image3)

}

When BROKEN is set to false it will use a working path that casts the enum to u32. When it is true it will break when create_image is defined, but won't have an issue if you comment it and the respective call out.

More elaborate, even more broken code here (txt extension because github wouldn't allow .odin)
bug.odin.txt

Failure Logs

For the simpler case:

Error: Array count must be a constant integer 
        size: [DIMENSION_COUNT[DIM]]int,

For the more elaborate case:

 Error: Cannot cast 'DIM' as 'int' from 'Dimension' 
        size: [1 + (int)(DIM)]int, 
                         ^~^ 
        '[View_Type]Dimension{.D1 = .D1, .D1_Array = .D1, .D2 = .D2, .D2_Array = .D2, .D3 = .D3, .Cube = .D2, .Cube_Array = .D2}' cannot be represented as the type 'int' 
Internal Compiler Error: match_exact_values: How'd you get here? Invalid ExactValueKind 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants