Skip to content

enhancement: support mutual recursion (forward function references) #550

Description

@t0k0sh1

Summary

Functions cannot reference other functions defined later in the same file, making mutual recursion impossible.

Reproduction

function is_even(n: int) -> bool:
    if n == 0:
        return true
    return is_odd(n - 1)   # Error: undefined function: is_odd

function is_odd(n: int) -> bool:
    if n == 0:
        return false
    return is_even(n - 1)

Expected behavior

Functions should be able to call each other regardless of definition order, either via:

  1. Two-pass resolution — collect all function signatures first, then resolve bodies
  2. Forward declarations — explicit declare function is_odd(n: int) -> bool

Impact

Mutual recursion is a common pattern for state machines, parsers, and tree traversal algorithms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions