From 7bca80313602f71febada8e551598c5a8625024f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 22 Dec 2025 23:51:41 +0300 Subject: [PATCH] Add scope level to return statement --- libs/ast/include/pslang/ast/statement.hpp | 1 + libs/parser/source/finilize.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libs/ast/include/pslang/ast/statement.hpp b/libs/ast/include/pslang/ast/statement.hpp index 9fa184a..246c4f9 100644 --- a/libs/ast/include/pslang/ast/statement.hpp +++ b/libs/ast/include/pslang/ast/statement.hpp @@ -35,6 +35,7 @@ namespace pslang::ast // can be null, which means "return unit" expression_ptr value; ast::location location; + std::size_t level = 0; }; using statement_impl = std::variant< diff --git a/libs/parser/source/finilize.cpp b/libs/parser/source/finilize.cpp index 6ae85dd..cd68e89 100644 --- a/libs/parser/source/finilize.cpp +++ b/libs/parser/source/finilize.cpp @@ -122,6 +122,7 @@ namespace pslang::parser { if (in_function_scope == 0) throw parse_error("Return statement outside of function scope", return_statement->location); + return_statement->level = stack.size() - in_function_scope; current_statement_list(location)->statements.push_back(std::move(statement.statement)); } else