Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Type specialization oddities

Open JesseRMeyer opened this issue 1 year ago • 0 comments

The overview makes use of language like "In some cases, you may want to specify that a type must be a specialization of a certain type." but there are instances where the behavior doesn't seem to match this and appears inconsistent. After a brief discussion with gB, we decided to track this issue here.

For example, this compiles, despite believing that only structs of type A would be permitted.

A :: struct {
    a: int
}

B:: struct {
    b: int
}

ChildOfA :: struct {
    using c: A
}

ListOfA :: struct($Item: typeid/A) {
    items: []Item
}

list := ListOfA(B) {
    items = []B{ B{ b = 1 }, B{ b = 2 } }
}

Furthermore, adding:

do_stuff :: proc($T: typeid/A, len: int) {

}

do_stuff(A, 12)

Results in "Cannot convert type A to the specialization A.

First reported by community member [GdR] obiwan87 on discord.

JesseRMeyer avatar May 02 '24 13:05 JesseRMeyer