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)]
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
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?
3 Replies
Helehex
Helehex11mo ago
seems like a bug works when you put the alias outside of the fn
Helehex
Helehex11mo ago
GitHub
[BUG]: Types in aliases do not work as expected · Issue #1028 · mod...
Bug description Using aliases for types produces errors unexpectedly, when the user would expect them to be essentially substituted. Steps to reproduce The following fails: fn nothing() -> None:...
Henk-Jan Lebbink
Henk-Jan Lebbink11mo ago
Thanx for digging; that issue is precisely my problem.
Want results from more Discord servers?
Add your server