diff --git a/src/typechecker.cpp b/src/typechecker.cpp index 7262438..84ad77a 100644 --- a/src/typechecker.cpp +++ b/src/typechecker.cpp @@ -27,11 +27,19 @@ namespace AST { } std::shared_ptr ValueReferenceExpression::typecheck( - typecheck::State&, + typecheck::State& state, typecheck::Scope& scope, std::optional> ) { - return scope.symbols[this->m_name]; + if (scope.symbols.contains(this->m_name)) { + return scope.symbols[this->m_name]; + } + else { + state.errors.push_back(CompileError("Value " + this->m_name + " not defined", this->m_meta)); + return std::shared_ptr{ + new types::FundamentalType{ types::FundamentalTypeKind::Void } + }; + } } std::shared_ptr BinaryOperationExpression::typecheck( @@ -78,6 +86,7 @@ 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. } void InitializationStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) { @@ -112,6 +121,7 @@ namespace AST { scope.symbols[this->m_name] = std::shared_ptr{ function_ty }; typecheck::Scope inner{ scope }; + inner.return_ty = return_ty; if (this->m_statements) { for (auto& statement : *this->m_statements) {