Odin icon indicating copy to clipboard operation
Odin copied to clipboard

matrix proc overload return value failure prevents other overload from being chosen

Open IanLilleyT opened this issue 3 years ago • 0 comments

Error: Matrix elements types are limited to integers, floats, and complex, got ^int

What seems to be happening is cast_mat is evaluated and sees an invalid return type of matrix[N,N]^int and this is preventing the correct overload cast_val from being chosen. Putting where N > 0 or where intrinsics.type_is_matrix(A) doesn't help.

Repro:

package main
main :: proc() { my_cast(rawptr{}, ^int) }
cast_mat :: proc(v: $A/matrix[$N, N]$T, $E: typeid) -> (w: matrix[N, N]E) { return }
cast_val :: proc(v: $T, $E: typeid) -> (w:E) { return }
my_cast :: proc {cast_mat, cast_val}

If you remove the return values from both procs it compiles fine, as expected

package main
main :: proc() { my_cast(rawptr{}, ^int) }
cast_mat :: proc(v: $A/matrix[$N, N]$T, $E: typeid) {}
cast_val :: proc(v: $T, $E: typeid) {}
my_cast :: proc {cast_mat, cast_val}

Likewise, if you remove cast_val it will correctly error with: Cannot determine polymorphic type from parameter: 'rawptr' to '$A/matrix[0, 0]$T'

package main
main :: proc() { cast_mat(rawptr{}, ^int) }
cast_mat :: proc(v: $A/matrix[$N, N]$T, $E: typeid) { return }

Report:

Odin: dev-2022-08:afec321d
OS:   Windows 11 Professional (version: 21H2), build 22000.856
CPU:  Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz

IanLilleyT avatar Aug 18 '22 20:08 IanLilleyT