Fix casting to same type

This commit is contained in:
Sofia 2025-07-22 14:21:17 +03:00
parent e27aa4b8ab
commit 9c0d373f9d

View File

@ -1030,22 +1030,25 @@ impl mir::Expression {
} }
mir::ExprKind::CastTo(expression, type_kind) => { mir::ExprKind::CastTo(expression, type_kind) => {
let val = expression.codegen(scope, state)?; let val = expression.codegen(scope, state)?;
let instr = if val.1 == *type_kind {
if let (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) = (&val.1, type_kind) { Some(val)
val.0.instr() } else if let (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) = (&val.1, type_kind) {
} else { Some(val)
let cast_instr = val } else {
.1 let cast_instr = val
.get_type(scope.type_values, scope.types) .1
.cast_instruction( .get_type(scope.type_values, scope.types)
val.instr(), .cast_instruction(
&type_kind.get_type(scope.type_values, scope.types), val.instr(),
) &type_kind.get_type(scope.type_values, scope.types),
.unwrap(); )
scope.block.build(cast_instr).unwrap() .unwrap();
};
Some(StackValue(val.0.derive(instr), type_kind.clone())) Some(StackValue(
val.0.derive(scope.block.build(cast_instr).unwrap()),
type_kind.clone(),
))
}
} }
}; };
if let Some(value) = &value { if let Some(value) = &value {