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) {