odin-lang / Odin

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

Unexpected Error when using parapoly varargs parameter #3176

Open kururen opened 8 months ago

kururen commented 8 months ago

Context

Expected Behavior

Declaring a varargs parameter that also declares use of a polymorphic should work in the same as if the polymorphic type was already define before (see examples); or an error message explaining why this isn't possible.

Current Behavior

A declaration like this proc(input: ..$T) -> T causes the following error at compile time: Ambiguous call to a polymorphic variadic procedure with no variadic input proc(..[]$T, string) -> []$T

Steps to Reproduce

Here is a minimal repro:

package bug

main :: proc() {
    sum(1)
}

sum :: proc(input: ..$T) -> (sum: T) {
    for i in input do sum += i
    return
}

The problem only appears if the $T is declared by the varargs parameter. The following example compiles and works as expected:

package works

main :: proc() {
    sum(int, 1, 2)
}

sum :: proc($T: typeid, input: ..T) -> (sum: T) {
    for i in input do sum += i
    return
}

Same if the first parameter is for example something like first: $T.

This was tested on both Windows and Mac and it fails in the same way.

mtarik34b commented 8 months ago

Same issue as #2826