ModularM
Modular3y ago
4 replies
Henk-Jan Lebbink

Type system does not recognize that a literal int is equal to an Int alias

I have a simple struct called Cube:

struct Cube[T: DType, N: Int]:
    var value: SIMD[T, (1 << N)]


I've simplified the code: what remains is the following issue. (Obviously, in this contrived example, N can just be replaced by 1), but for real-world code, I cannot.

fn reflectN1[T: DType]() -> Cube[T, 1] :
    alias N: Int = 1
    var x : Cube[T, N] = Cube[T, N]()
    x.value[0] = 1
    x.value[1] = 0
    return x


Error: cannot implicitly convert 'Cube[T, N]' value to 'Cube[T, 1]' in return value

mojo 0.4.0 (9e33b013)

Question: Does anyone know how to cast my x (of type Cube[T, N] to Cube[T, 1]? Or is there another way to get the type system to accept this?
Was this page helpful?