mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[BUG] Inconsistent behavior of `let` declarations for Strings

Open jusevitch opened this issue 1 year ago • 1 comments

Bug Description

String variables declared with let are mutable.

It's not clear whether the behavior below is intended or not. However, it's surprising that the code below runs since variables declared with let are in principle supposed to be immutable.

Steps to Reproduce

  1. Run the following code in the online Jupyter notebook:
from String import String

let x: String
x = "This is x's original value"
print(x)
x = "This is x's new value"
print(x)
let z: String = "This is z's value"
x = z
print(x)

Output:

This is x's original value
This is x's new value
This is z's value

Context

Context output
11:blkio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 10:devices:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 9:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 8:freezer:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 7:cpu,cpuacct:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 6:memory:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 5:hugetlb:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 4:pids:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 3:perf_event:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 2:net_cls,net_prio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podd921e586_ac57_4bc0_8214_532b75b5e678.slice/cri-containerd-ac03f8788fbcd310828d9d21d49717be4aeb81df1f5c164c836c2b0e3cb9f813.scope 0::/

jusevitch avatar May 07 '23 05:05 jusevitch

This problem is specific to top-level code in notebooks fyi @River707

Possibly related to https://github.com/modularml/mojo/issues/15

Mogball avatar May 07 '23 10:05 Mogball

This is possibly the correct behaviour of let declarations in top-level code: in top-level code, redefinitions are allowed. For example, you can redeclare structs and methods. It doesn't seem correct that let x in a notebook means x can never be redeclared/defined, ever. LMKWYT

Mogball avatar May 11 '23 13:05 Mogball

Yes, I too think that this let x declaration seem to mean that x can never be redeclared

gullayeshwantkumarruler avatar May 12 '23 16:05 gullayeshwantkumarruler

This is a duplicate of #15, folding it into that just so we have one issue to track

lattner avatar May 13 '23 09:05 lattner