Fix some bugs
This commit is contained in:
parent
5ed26f4139
commit
cf965dd47a
@ -27,11 +27,19 @@ namespace AST {
|
||||
}
|
||||
|
||||
std::shared_ptr<types::Type> ValueReferenceExpression::typecheck(
|
||||
typecheck::State&,
|
||||
typecheck::State& state,
|
||||
typecheck::Scope& scope,
|
||||
std::optional<std::shared_ptr<types::Type>>
|
||||
) {
|
||||
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<types::Type>{
|
||||
new types::FundamentalType{ types::FundamentalTypeKind::Void }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<types::Type> 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<types::Type>{ function_ty };
|
||||
|
||||
typecheck::Scope inner{ scope };
|
||||
inner.return_ty = return_ty;
|
||||
|
||||
if (this->m_statements) {
|
||||
for (auto& statement : *this->m_statements) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user