diff --git a/src/typechecker.cpp b/src/typechecker.cpp index cd2cf49..4f255c0 100644 --- a/src/typechecker.cpp +++ b/src/typechecker.cpp @@ -645,20 +645,22 @@ namespace AST { auto bool_ty = std::shared_ptr{ 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) {