Skip to content

Conversation

@Rafael-Sapienza
Copy link
Owner

No description provided.

Previously, new_env was not receiving functions from the outer environment,
which caused external functions to be inaccessible inside function bodies.
This also broke recursion, since the function itself wasn't visible in its own scope.

This commit ensures that external functions are copied into new_env,
allowing function bodies to reference both external and self-defined functions.
…nal block execution

Fixes a scoping bug in execute_block where pop() was applied to the wrong environment.

Previously, in function `exec`:
- The environment `env` was cloned into a variable `new_env`.
- In the `Statement::Block` match arm, the returned environment was actually wrapped inside
  the variable `result`, of type `Computation`.
- However, `pop()` was mistakenly called on `new_env`, which was discarded afterward.
- As a result, the environment inside `result` — the one that was actually returned —
  remained unmodified, and the pushed scope was never popped.

This commit fixes the issue by:
- Moving the push/pop operations into the `execute_block` function itself,
  so that scope management is handled consistently before wrapping the result in a `Computation`.

Additionally, it introduces the `exec_if_block` function:
- A simplified version of `execute_block` that executes a list of statements without
  pushing or popping a new scope.
- Intended for use in the body of `if` clauses

These changes improve correctness and modularity in the interpreter's handling of scope and control flow.
…e return and function definition

- Created `check_block_stmt` to handle scoped type checking of block statements
- Created `check_func_call` to validate function call expressions
- Updated `check_return_stmt` to ensure return type matches declared function type
- Improved `check_func_def_stmt` to handle duplicate declarations and parameter validation

These changes improve the accuracy and robustness of the type checker.
@Rafael-Sapienza Rafael-Sapienza merged commit f6f4666 into main Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants