Draft
Conversation
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Mutual recursion does not work
Fix mutual recursion support in type inference
Sep 17, 2025
✅ Binary Size Check PassedBinary Size Comparison ReportNo significant binary size changes were detected in this PR. This report compares the binary sizes of compiled contracts against the baseline from the latest release. |
nielstron
requested changes
Sep 17, 2025
Contributor
|
Note that a proper fix for #522 requires this fix too. |
It seems that the compiler does not correctly handle this though
Contributor
|
@copilot can you look at my changes and take it from there? |
…d test cases for nested functions and classes Co-authored-by: nielstron <20638630+nielstron@users.noreply.github.com>
Contributor
Author
Addressed the generality concerns by accepting @nielstron's refactor to visit_sequence() and added test cases for nested functions and classes. Fixed formatting and removed unrelated changes in commit f7d9d20. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes mutual recursion support in OpShin by implementing a two-pass type inference approach that works for all function scopes.
Problem
Previously, mutual recursion would fail to compile because the type inference system processed functions sequentially. When an earlier function tried to call a later-defined function, the later function wasn't yet in scope:
Solution
Implemented a two-pass approach in
AggressiveTypeInferencer.visit_sequence():This ensures that all function names are available before any function bodies are processed, enabling mutual recursion at any scope level.
Key Features
Test Coverage
Added comprehensive test cases covering:
The fix handles various mutual recursion scenarios while maintaining full backward compatibility with existing code.
Fixes #524.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.