Fix some bugs

This commit is contained in:
Sofia 2026-04-13 16:50:29 +03:00
parent 5ed26f4139
commit cf965dd47a

View File

@ -27,12 +27,20 @@ namespace AST {
} }
std::shared_ptr<types::Type> ValueReferenceExpression::typecheck( std::shared_ptr<types::Type> ValueReferenceExpression::typecheck(
typecheck::State&, typecheck::State& state,
typecheck::Scope& scope, typecheck::Scope& scope,
std::optional<std::shared_ptr<types::Type>> std::optional<std::shared_ptr<types::Type>>
) { ) {
if (scope.symbols.contains(this->m_name)) {
return scope.symbols[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<types::Type>{
new types::FundamentalType{ types::FundamentalTypeKind::Void }
};
}
}
std::shared_ptr<types::Type> BinaryOperationExpression::typecheck( std::shared_ptr<types::Type> BinaryOperationExpression::typecheck(
typecheck::State& state, typecheck::State& state,
@ -78,6 +86,7 @@ namespace AST {
void ReturnStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) { void ReturnStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) {
this->m_expr->typecheck(state, scope, scope.return_ty); 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) { void InitializationStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) {
@ -112,6 +121,7 @@ namespace AST {
scope.symbols[this->m_name] = std::shared_ptr<types::Type>{ function_ty }; scope.symbols[this->m_name] = std::shared_ptr<types::Type>{ function_ty };
typecheck::Scope inner{ scope }; typecheck::Scope inner{ scope };
inner.return_ty = return_ty;
if (this->m_statements) { if (this->m_statements) {
for (auto& statement : *this->m_statements) { for (auto& statement : *this->m_statements) {