modularml / mojo

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

[BUG]: mutations and print related #881

Open rd4com opened 11 months ago

rd4com commented 11 months ago

Bug description

Ok, because Jeff ask for bug reports in the Q/A :p

fn get_copy(borrowed p:object)->object:
    return p

fn main() raises:
    var o:object=object(Attr("value",None))

    var p = get_copy(o)

    p.value = 2
    print(o)        #mutated (i think it is quite cool and ruby like, but dont know if it is expected behaviour)

    #p.value = p 
    #print(o)       #infinite loop at runtime (Segmentation fault (core dumped)), comptime don't complain

i think those builtin lightweight objects are fantastic, it is quite cool to have those dynamic features. especially in the future use cases of wasm and where size matter in general like micro controllers. they can speed up productivity when speed is not required, like prototyping. is there any roadmap for them ? is it ok to use them ? keep up the good work

Steps to reproduce

System information

- ubuntu
- mojo 0.3.0
- modular 0.1.4
Mogball commented 11 months ago

Thanks for filing @rd4com ! This looks like infinite recursion in the print indeed. I can go add a safeguard

rd4com commented 11 months ago

@Mogball do i need to close the issue ? i don't really know github issues lol

Mogball commented 11 months ago

You've reported a real problem, which means the issue will get closed when we fix it :P