Fix wonky casting rules

This commit is contained in:
Sofia 2026-04-14 20:02:06 +03:00
parent de881d73d2
commit 5175878407

View File

@ -63,6 +63,10 @@ namespace AST {
std::shared_ptr<types::Type> ValueReferenceExpression::get_codegen_type(codegen::Scope& scope) { std::shared_ptr<types::Type> ValueReferenceExpression::get_codegen_type(codegen::Scope& scope) {
auto value = scope.values.find(this->m_name); auto value = scope.values.find(this->m_name);
if (value != scope.values.end()) { if (value != scope.values.end()) {
if (value->second.ty->m_kind == types::TypeKind::Pointer) {
auto ptr_ty = dynamic_cast<types::PointerType*>(value->second.ty.get());
return ptr_ty->m_inner;
}
return value->second.ty; return value->second.ty;
} }
else { else {
@ -167,10 +171,8 @@ namespace AST {
codegen::StackValue CastExpression::codegen(codegen::Builder& builder, codegen::Scope& scope) { codegen::StackValue CastExpression::codegen(codegen::Builder& builder, codegen::Scope& scope) {
auto expr_ty = this->m_expr->get_codegen_type(scope); auto expr_ty = this->m_expr->get_codegen_type(scope);
if ((expr_ty->m_kind == types::TypeKind::Array if (expr_ty->m_kind == types::TypeKind::Array
|| expr_ty->m_kind == types::TypeKind::Pointer)
&& this->m_ty->m_kind == types::TypeKind::Pointer) { && this->m_ty->m_kind == types::TypeKind::Pointer) {
std::cout << expr_ty->formatted() << std::endl;
auto lvalued = scope.with_lvalue(); auto lvalued = scope.with_lvalue();
auto expr = this->m_expr->codegen(builder, lvalued); auto expr = this->m_expr->codegen(builder, lvalued);
auto cast = types::find_cast(scope.casts, expr.ty, this->m_ty); auto cast = types::find_cast(scope.casts, expr.ty, this->m_ty);