Fix borrow derefs

This commit is contained in:
Sofia 2025-07-23 17:52:28 +03:00
parent fe4e41c435
commit c622d59c93
3 changed files with 18 additions and 18 deletions

View File

@ -2,7 +2,7 @@
struct Test { struct Test {
field: i32, field: i32,
second: [u32; 4] second: [u32; 4],
} }
fn test() -> Test { fn test() -> Test {
@ -18,13 +18,7 @@ fn main() -> u32 {
let mut a = &mut value; let mut a = &mut value;
*a.second[2] = 15; let test = *a.field;
let b = 4;
if value.field < b {
return 0; return 0;
} }
return value.second[2];
}

View File

@ -440,6 +440,7 @@ impl Builder {
} }
Instr::GetStructElemPtr(ptr_val, idx) => { Instr::GetStructElemPtr(ptr_val, idx) => {
let ptr_ty = ptr_val.get_type(&self)?; let ptr_ty = ptr_val.get_type(&self)?;
dbg!(&ptr_ty);
if let Type::Ptr(ty) = ptr_ty { if let Type::Ptr(ty) = ptr_ty {
if let Type::CustomType(val) = *ty { if let Type::CustomType(val) = *ty {
match self.type_data(&val).kind { match self.type_data(&val).kind {

View File

@ -256,7 +256,6 @@ impl mir::Module {
let mut typedefs = self.typedefs.clone(); let mut typedefs = self.typedefs.clone();
typedefs.sort_by(|a, b| b.source_module.cmp(&a.source_module)); typedefs.sort_by(|a, b| b.source_module.cmp(&a.source_module));
dbg!(&self.module_id, &typedefs);
for typedef in typedefs { for typedef in typedefs {
let type_key = CustomTypeKey(typedef.name.clone(), typedef.source_module); let type_key = CustomTypeKey(typedef.name.clone(), typedef.source_module);
let type_value = match &typedef.kind { let type_value = match &typedef.kind {
@ -1001,6 +1000,7 @@ impl mir::Expression {
let TypeKind::CodegenPtr(inner) = &struct_val.1 else { let TypeKind::CodegenPtr(inner) = &struct_val.1 else {
panic!("tried accessing non-pointer"); panic!("tried accessing non-pointer");
}; };
dbg!(&inner);
let TypeKind::CustomType(key) = *inner.clone() else { let TypeKind::CustomType(key) = *inner.clone() else {
panic!("tried accessing non-custom-type"); panic!("tried accessing non-custom-type");
}; };
@ -1097,9 +1097,14 @@ impl mir::Expression {
.stack_values .stack_values
.get(&varref.1) .get(&varref.1)
.expect("Variable reference not found?!"); .expect("Variable reference not found?!");
let TypeKind::CodegenPtr(ptr_inner) = &v.1 else {
panic!();
};
Some(StackValue( Some(StackValue(
StackValueKind::mutable(*mutable, v.0.instr()), StackValueKind::mutable(*mutable, v.0.instr()),
TypeKind::Borrow(Box::new(v.1.clone()), *mutable), TypeKind::Borrow(Box::new(*ptr_inner.clone()), *mutable),
)) ))
} }
mir::ExprKind::Deref(varref) => { mir::ExprKind::Deref(varref) => {