modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.02k stars 2.59k forks source link

[BUG] RPL gets chars from a String pointer correctly, Mojo file does it wrong #3482

Closed msaelices closed 3 weeks ago

msaelices commented 3 weeks ago

Bug description

You can see it in the following screenshot:

2024-09-14_11-31

Steps to reproduce

Tested with the following snippet:

var s = String("ab")
p = s.unsafe_ptr()
c = chr(int(p.load()))
print('Char: ', c)

System information

❯ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"
❯ mojo --version
mojo 2024.9.1305 (6ceeec48)
msaelices commented 3 weeks ago

Ok, I think it's not an issue but the fact of the s string is freed when we are using the unsafe pointer, which is legit as the pointer is actually unsafe. The REPL retain the value of the string