From e3e0cd9f9f8e735cb69f521eaf5e3e40601f9fec Mon Sep 17 00:00:00 2001 From: Sofia Date: Mon, 13 Apr 2026 17:25:36 +0300 Subject: [PATCH] Check return type as well --- src/typechecker.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/typechecker.cpp b/src/typechecker.cpp index 188bc16..fb2826e 100644 --- a/src/typechecker.cpp +++ b/src/typechecker.cpp @@ -131,8 +131,11 @@ namespace AST { } void ReturnStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) { - this->m_expr->typecheck(state, scope, scope.return_ty); - // TODO make sure returned type matches function return type. + auto res_ty = this->m_expr->typecheck(state, scope, scope.return_ty); + if (scope.return_ty) { + auto check_res = check_type(res_ty, *scope.return_ty); + this->m_expr = handle_res(std::move(this->m_expr), check_res, state); + } } void InitializationStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) {