odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.55k stars 570 forks source link

Bad error message in SOA slice compound literals #3515

Closed jakubtomsu closed 2 months ago

jakubtomsu commented 4 months ago

Context

        Odin:    dev-2024-03-nightly:4c35633e0
        OS:      Windows 10 Professional (version: 22H2), build 19045.4291
        CPU:     Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
        RAM:     32681 MiB
        Backend: LLVM 17.0.1

Current Behavior

The current SOA slice initializer list errors are incorrect, unlike fixed arrays and dynamic arrays.

Foo :: struct {
    a: f32,
    b: f32,
}

foos := #soa[]Foo{{1, 2}, {3, 4}, {5, 6}}

This code results in:

Error: Invalid compound literal type '^f32'
        foos := #soa[]Foo{{1, 2}, {3, 4}, {5, 6}}
                          ^~~~~^
Error: Invalid compound literal type '^f32'
        foos := #soa[]Foo{{1, 2}, {3, 4}, {5, 6}}
                                  ^~~~~^
Error: Illegal compound literal, int cannot be used as a compound literal with fields
        foos := #soa[]Foo{{1, 2}, {3, 4}, {5, 6}}
                                          ^~~~~^

However, fixed and dynamic SOA arrays let the user know compound literals just aren't supported:

foos2 := #soa[2]Foo{{1, 2}, {3, 4}, {5, 6}}
Error: #soa arrays are not supported for compound literals
        foos2 := #soa[2]Foo{{1, 2}, {3, 4}, {5, 6}}
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
jakubtomsu commented 4 months ago

This might be related to https://github.com/odin-lang/Odin/issues/3514 because the compiler attempts to use the internal pointers as members in the initializer list

gingerBill commented 4 months ago

This issue and #3514 are actually unrelated since they can be handled completely differently.