I suspect this may be a deeper issue. but the easy way to manifest that something is amiss is to create a 'memory-only' object, and then have a @parameter-bound callable use that. If the object is not referenced anywhere after the function call, you may 'get lucky' and Mojo decides to 'clean up' the object prior to actual use.
A smallest repro case is included below:
fn main():
let simpler = String("I want you to hold this")
@parameter
fn doit():
for i in range(len(simpler)-5):
print(simpler[i:i+5])
doit()
# If uncommented, this will actually work correctly
#print(len(simpler))
Steps to reproduce
Anytime when you declare a non-trivial object and use it in @parameter bound function, the memory may be gone
This works with anything ranging from Strings to custom-allocated structs, through Pointers
Seems to be broken even if Pointer is purposefully not deallocated (does Mojo clean up unused Pointers? hard to say)
System information
- What OS did you do install Mojo on ?
Win 11 / WSL2 / Ubuntu 23.04
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 0.6.0 (d55c0025)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.2.2 (95d42445)
Bug description
I suspect this may be a deeper issue. but the easy way to manifest that something is amiss is to create a 'memory-only' object, and then have a
@parameter
-bound callable use that. If the object is not referenced anywhere after the function call, you may 'get lucky' and Mojo decides to 'clean up' the object prior to actual use. A smallest repro case is included below:Steps to reproduce
System information