Fix bug with typecheckign for-loops

This commit is contained in:
Sofia 2026-04-28 01:47:49 +03:00
parent 941e19d4dd
commit 9817d9b8b6

View File

@ -645,20 +645,22 @@ namespace AST {
auto bool_ty = std::shared_ptr<types::Type>{
new types::FundamentalType{ false, types::FundamentalTypeKind::Bool } };
typecheck::Scope inner_scope{ scope };
if (this->m_init)
(*this->m_init)->typecheck(state, scope);
(*this->m_init)->typecheck(state, inner_scope);
if (this->m_cond) {
auto cond_ty = (*this->m_cond)->typecheck(state, scope, bool_ty).type;
auto cond_ty = (*this->m_cond)->typecheck(state, inner_scope, bool_ty).type;
auto check_res = check_type(state, cond_ty, bool_ty);
this->m_cond = handle_res(std::move(*this->m_cond), check_res, state);
}
if (this->m_after)
(*this->m_after)->typecheck(state, scope, {});
(*this->m_after)->typecheck(state, inner_scope, {});
this->m_loop->typecheck(state, scope);
this->m_loop->typecheck(state, inner_scope);
}
void Function::typecheck_preprocess(typecheck::Scope& scope) {