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
When writing a loop, we're facing a weird issue from the compiler saying that Identifier not found for a variable that is actually defined in the loop itself:
implBattleImpl of BattleTrait{fnbattle_loop(refself:Battle){loop{letmut entity:u32 = 5;if !self.isAlly(entity){break;}};}fnis_ally(refself:Battle,entity_index:u32) -> bool{returntrue;}}
This fails with:
error: Identifier not found.
--> /home/glihm7a/Downloads/mre/src/Battle.cairo:20:29
if !self.isAlly(entity) {
^****^
But defining the variable outside the loop, or adding a statement solves the problem:
implBattleImpl of BattleTrait{fnbattle_loop(refself:Battle){loop{// Moving this out of the loop makes the code compile.letmut entity:u32 = 5;if !self.isAlly(entity){break;}// This makes the code compile.let a = 2;};}fnis_ally(refself:Battle,entity_index:u32) -> bool{returntrue;}}
Expected behavior:
Expecting the variable defined inside the loop to be found without adding an extra statement.
Steps to reproduce:
Here is a MRE:
#[derive(Destruct)]structBattle{}fnnew() -> Battle{letmut battle = Battle{};return battle;}traitBattleTrait{fnbattleLoop(refself:Battle);fnisAlly(refself:Battle,entityIndex:u32) -> bool;}implBattleImpl of BattleTrait{fnbattleLoop(refself:Battle){loop{letmut entity:u32 = 5;if !self.isAlly(entity){break;}//let b = 2;};}fnisAlly(refself:Battle,entityIndex:u32) -> bool{returntrue;}}
Related code:
Not sure of the compiler code related to that. Any hints on this and I would be happy to investigate.
Other information:
At the beginning I was thinking of the fact that as the entity variable is related to the break, cairo needs to know it outside the loop.
But when we add a statement, it works. So I'm not sure of the behavior here.
Speaking with Oriz on the discord, he is likely a bug, but no clue where on my side.
The text was updated successfully, but these errors were encountered:
Bug Report
Cairo version:
v2.3.0
Current behavior:
When writing a loop, we're facing a weird issue from the compiler saying that
Identifier not found
for a variable that is actually defined in the loop itself:This fails with:
But defining the variable outside the loop, or adding a statement solves the problem:
Expected behavior:
Expecting the variable defined inside the loop to be found without adding an extra statement.
Steps to reproduce:
Here is a MRE:
Related code:
Not sure of the compiler code related to that. Any hints on this and I would be happy to investigate.
Other information:
At the beginning I was thinking of the fact that as the
entity
variable is related to the break, cairo needs to know it outside the loop.But when we add a statement, it works. So I'm not sure of the behavior here.
Speaking with Oriz on the discord, he is likely a bug, but no clue where on my side.
The text was updated successfully, but these errors were encountered: