diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 9a2c9e5110..834ce77b36 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -671,6 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm) RUN(NAME func_static_02 LABELS cpython llvm c wasm) RUN(NAME func_dep_03 LABELS cpython llvm c) RUN(NAME func_dep_04 LABELS cpython llvm c) +RUN(NAME func_internal_def_01 LABELS cpython llvm NOFAST) RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64) RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86) diff --git a/integration_tests/func_internal_def_01.py b/integration_tests/func_internal_def_01.py new file mode 100644 index 0000000000..1c0c1d11e5 --- /dev/null +++ b/integration_tests/func_internal_def_01.py @@ -0,0 +1,11 @@ +def main(): + x: i32 + x = (2+3)*5 + print(x) + + def bar(): + assert x == 25 + + bar() + +main() diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1345625051..e6ba523b23 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4060,6 +4060,24 @@ class SymbolTableVisitor : public CommonVisitor { return nullptr; } + // Implement visit_While for Symbol Table visitor. + void visit_While(const AST::While_t &/*x*/) {} + + // Implement visit_Delete for Symbol Table visitor. + void visit_Delete(const AST::Delete_t &/*x*/) {} + + // Implement visit_Pass for Symbol Table visitor. + void visit_Pass(const AST::Pass_t &/*x*/) {} + + // Implement visit_Return for Symbol Table visitor. + void visit_Return(const AST::Return_t &/*x*/) {} + + // Implement visit_Raise for Symbol Table visitor. + void visit_Raise(const AST::Raise_t &/*x*/) {} + + // Implement visit_Global for Symbol Table visitor. + void visit_Global(const AST::Global_t &/*x*/) {} + void visit_FunctionDef(const AST::FunctionDef_t &x) { dependencies.clear(al); SymbolTable *parent_scope = current_scope; @@ -4304,6 +4322,12 @@ class SymbolTableVisitor : public CommonVisitor { } } else { bool is_pure = false, is_module = false; + + // This checks for internal function defintions as well. + for (size_t i = 0; i < x.n_body; i++) { + visit_stmt(*x.m_body[i]); + } + tmp = ASRUtils::make_Function_t_util( al, x.base.base.loc, /* a_symtab */ current_scope,