You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think this is a desirable fix for this problem. Python allows all sorts of weird getitem/setitem things, and Mojo doesn't want to impose "taste" (or even "common sense" :-) ) on library authors.
The issue here is that referring to the alias value "materializes" it into a local, so the code is like:
fn main():
alias foo = S(0)
var tmp1 = foo
tmp1[] = 10
var tmp2 = foo
print(tmp2[]) # prints 0
The behavior is a bit surprising but stacks out from how other parts of the language works.
soraros
changed the title
[BUG] Mojo should block mutating __getitem__ -> ref ... call
[BUG] Mojo should block mutating __getitem__ -> ref ... call on aliasJul 29, 2024
@valuestructS:
vardata: Int
fn__setitem__(inoutself, value: Int):
self.data = value
fnmain():
aliasfoo= S(0) # error: invalid call to '__setitem__': invalid use of mutating method on rvalue of type 'S'
foo[] =10print(foo[]) # prints 0
Bug description
As title.
Steps to reproduce
System information
The text was updated successfully, but these errors were encountered: