Files
Odin/tests/issues/test_issue_poly_proc_value.odin
T
bbodi 9f62e02634 Reject casts of unspecialized polymorphic procs
Casting a polymorphic procedure to `rawptr`, or to a procedure type
it cannot be specialized to, was accepted. There is no procedure to
take the address of, so the value came out nil, or the build hung, as
with `x := rawptr(avl.init_cmp)`. Assigning one to `rawptr` already
errors; make `cast` and `transmute` match. Casting to a procedure type
that specializes it still works, as assignment does.
2026-10-08 15:51:24 +02:00

21 lines
660 B
Odin

// A polymorphic procedure has no value until it is specialized. Casting or transmuting one
// was accepted and then hung the build or produced nil; each must be an error.
package test_issues
import "core:container/avl"
poly :: proc(a: $T) -> T { return a }
global := rawptr(avl.init_cmp) // error
main :: proc() {
a := rawptr(poly) // error
b := cast(proc(string, int))poly // error
c := transmute(rawptr)poly // error
// casting to a procedure type it can be specialized to still works
d := cast(proc(int) -> int)poly
_, _, _, _, _ = global, a, b, c, d
}