[BUG] Accessing aliased list of lists gives nonsense
Bug description
I also tried with VariadicList, and InlineArray. Both of those work fine.
If you use var entry = ll[1][1] instead of alias entry = ll[1][1], it works. (see example)
Steps to reproduce
fn main():
alias ll = List(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9))
alias entry = ll[1][1]
# var entry = ll[1][1]
print(entry)
# prints nonsense
System information
Host Information
================
Target Triple: x86_64-unknown-linux
CPU: skylake
CPU Features: adx, aes, avx, avx2, bmi, bmi2, clflushopt, cmov, crc32, cx16, cx8, f16c, fma, fsgsbase, fxsr, invpcid, lzcnt, mmx, movbe, pclmul, popcnt, prfchw, rdrnd, rdseed, sahf, sgx, sse, sse2, sse3, sse4.1, sse4.2, ssse3, x87, xsave, xsavec, xsaveopt, xsaves
mojo 2024.9.315 (62cda08f)
modular 0.9.2 (b3079bd5)
More of an issue with UnsafePointer[UnsafePointer[...]] in general though:
fn init() -> UnsafePointer[UnsafePointer[Int]]:
var ptr = UnsafePointer[Int].alloc(1)
ptr[] = 5
var ptrptr = UnsafePointer[UnsafePointer[Int]].alloc(1)
ptrptr[] = ptr
return ptrptr
fn main():
alias p = init()
alias entry = p[][] # prints nonsense
# var entry = p[][] # prints 5
print(entry)
Seems like the same root cause of an issue I raised as well https://github.com/modularml/mojo/issues/3285
@helehex This seems to be resolved. It prints 5 using 24.6.0.dev2024120416
Would this fall into this bug issue? kinda trying to make a couple of dictionaries lol:
# Build dictionaries
var keypad_dict = Dict[String, String]()
for i, row in enumerate(keypad):
for j, c in enumerate(row):
keypad_dict[c] = (i, j)
var arrows_dict = Dict[String, String]()
for i, row in enumerate(arrows):
for j, c in enumerate(row):
arrows_dict[c] = (i, j)
@rcghpge Could you elaborate what you meant? We don't have support for enumerate yet, maybe you want to create a feature request?
@rcghpge Could you elaborate what you meant? We don't have support for
enumerateyet, maybe you want to create a feature request?
oh no i might have opened up a can of worms x) my code block may be littered with bugs x) I've read the contributing guides on the repo and it seems very in-depth afaik. I posted this specific bug here because it popped a ListLiteral error:
error: 'ListLiteral[List[String], List[String], List[String], List[String]]' is not subscriptable, it does not implement the `__getitem__`/`__setitem__` methods
for j in range(len(keypad[i])):
~~~~~~^
Seem to be fixed on mojo 25.4.0.dev2025050206 (681f7fd5).