#Why does this parapoly not work with only the enum type?

5 messages · Page 1 of 1 (latest)

meager gate
#

Why does this parapoly not work with only the enum type?

#

Why does the ParaPoly below not work for enums? Does it need a specialization?
It is only not working when the first pointer is received through new() vs. taking the address operator twice (at bottom of code below).

package main
import "core:fmt"
main :: proc() {
    p_enum := new(enum {})
    pp_enum := &p_enum

    p_int := new(int)
    pp_int := &p_int
    
    enum1 := new(enum{})
    p_enum1 := &enum1
    pp_enum1 := &p_enum1

    print_p :: proc(pp: ^^$T) {
        fmt.println(pp)
    }

    fmt.println(pp_int)   // 0x23DA6FF810
    print_p(pp_int)       // 0x23DA6FF810

    fmt.println(pp_enum)  // 0x23DA6FF838
    print_p(pp_enum)      // Error: Cannot assign value 'pp_enum' of type '^^enum int {}' to '^^enum int {}' in a procedure argument
    
    fmt.println(pp_enum1) // 0x18D08FFCC0
    print_p(pp_enum1)     // 0x18D08FFCC0 
}
unkempt jungle
#

Every enum type, including anonymous ones, are unique. a: enum {} & b: enum {} have different types. Rather then using the actual anon type given, parapoly seems to be making an new anon type. i'd bet on it not being a bug & just the way odin's parapoly works.

#

explicitly getting & setting the type works fine. so it defiantly to with the way parpoly deals with anon types at the very least.

foo :: proc($T: typeid, v: T) {
    fmt.println(typeid_of(T), v)
}
a: enum{}
foo(type_of(a), a)
#

as a note: the pointers are just clutter here & don't change anything.