-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Description
Declaring a const followed by a var in the same function causes a Cranelift panic: the variable var0 has been declared multiple times.
Steps to Reproduce
fn main() {
const axx: int = 2;
var x: int = 10;
}
Expected: Compiles and runs
Actual: Panic: the variable var0 has been declared multiple times
Root Cause
In namlc/src/codegen/cranelift/mod.rs:
Statement::Varcorrectly usesVariable::new(ctx.var_counter)and incrementsctx.var_counter(line 1721-1722)Statement::Constincorrectly usesVariable::new(ctx.variables.len())and does NOT incrementctx.var_counter(line 2478)
When const is the first statement, variables.len() == 0 assigns Variable(0). Since var_counter is never incremented, the next var also gets Variable(0), causing the Cranelift panic.
Fix
Change Statement::Const to use ctx.var_counter and increment it, matching the Statement::Var pattern:
let var = Variable::new(ctx.var_counter);
ctx.var_counter += 1;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels