From 8e16140b0fdee08f36422f9b870098dabf000dbd Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 24 May 2023 01:00:42 +0200 Subject: [PATCH] fixed oversight --- mers/src/lang/code_parsed.rs | 4 +++- mers/src/lang/to_runnable.rs | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mers/src/lang/code_parsed.rs b/mers/src/lang/code_parsed.rs index 00151bc..871a014 100755 --- a/mers/src/lang/code_parsed.rs +++ b/mers/src/lang/code_parsed.rs @@ -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, usize)>, pub statement: Box, pub force_output_type: Option, diff --git a/mers/src/lang/to_runnable.rs b/mers/src/lang/to_runnable.rs index 435287a..267d2c1 100755 --- a/mers/src/lang/to_runnable.rs +++ b/mers/src/lang/to_runnable.rs @@ -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))]