Open artemiogr97 opened 1 month ago
This isn't necessarily a bug. It's unclear how the walrus operator should work in Mojo. If the variable didn't previously exist, maybe the following syntax should be required: if var j := i+1:
.
Just talking about variable declaration (not initialization), I guess guess it makes sense to have the same behavior as something like "for i in range(10):" where it is not needed to declare the "i" variable. I'm not against using var with the operator.
Personally I was just asked to create an issue for this by a maintainer.
Bug description
For now it is needed to declare a variable before being usable with the walrus operator
Steps to reproduce
The following code works:
It should be possible to do:
See comment here: https://github.com/modularml/mojo/pull/2742#discussion_r1615198526
System information