Fixed const -> let bug
All checks were successful
CI/CD Pipeline / test (pull_request) Successful in 33s
CI/CD Pipeline / build (pull_request) Has been skipped
CI/CD Pipeline / release (pull_request) Has been skipped

This commit is contained in:
2025-12-29 02:31:23 -07:00
parent 3ca6f97db1
commit f679601818
7 changed files with 40 additions and 5 deletions

View File

@@ -168,3 +168,28 @@ fn test_const_hash_expr() -> anyhow::Result<()> {
);
Ok(())
}
#[test]
fn test_declaration_is_const() -> anyhow::Result<()> {
let compiled = compile! {
debug
r#"
const MAX = 100;
let max = MAX;
"#
};
assert_eq!(
compiled,
indoc! {
"
j main
main:
move r8 100
"
}
);
Ok(())
}

View File

@@ -714,7 +714,12 @@ impl<'a> Compiler<'a> {
Operand::Register(VariableScope::TEMP_STACK_REGISTER)
}
VariableLocation::Constant(_) | VariableLocation::Device(_) => unreachable!(),
VariableLocation::Constant(Literal::Number(num)) => Operand::Number(num.into()),
VariableLocation::Constant(Literal::Boolean(b)) => {
Operand::Number(Number::from(b).into())
}
VariableLocation::Device(_)
| VariableLocation::Constant(Literal::String(_)) => unreachable!(),
};
self.emit_variable_assignment(&var_loc, src)?;
(var_loc, None)