fixed oversight

This commit is contained in:
mark 2023-05-24 01:00:42 +02:00
parent c32419508e
commit 8e16140b0f
2 changed files with 6 additions and 5 deletions

View File

@ -38,7 +38,9 @@ impl SStatementEnum {
#[derive(Debug)]
pub struct SStatement {
// if the statement is a Variable (is_ref == false) and it isn't dereferenced, it will be initialized. To modify a variable, it has to be is_ref.
/// if the statement is a Variable that doesn't exist yet, it will be initialized.
/// if it's a variable that exists, but is_ref is false, an error may show up: cannot dereference
/// NOTE: Maybe add a bool that indicates a variable should be newly declared, shadowing old ones with the same name.
pub output_to: Option<(Box<SStatement>, usize)>,
pub statement: Box<SStatementEnum>,
pub force_output_type: Option<VType>,

View File

@ -371,10 +371,9 @@ fn statement_adv(
}
SStatementEnum::Variable(v, is_ref) => {
let existing_var = linfo.vars.get(v);
// we can't assign to something that isn't a reference, so create a new variable shadowing the old one.
// we also can't assign to a variable that doesn't exist yet, so create a new one in that case, too.
if (!*is_ref && to_be_assigned_to.is_some()) || existing_var.is_none() {
// if to_be_assigned_to is some (-> this is on the left side of an assignment), create a new variable. else, return an error (later).
// we can't assign to a variable that doesn't exist yet -> create a new one
if existing_var.is_none() {
// if to_be_assigned_to is some (-> this is on the left side of an assignment), create a new variable. else, return an error.
if let Some((t, is_init)) = to_be_assigned_to {
*is_init = true;
#[cfg(not(debug_assertions))]