Skip to content

Fix: Stack overflow while attempting to resolve function return value #3247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025

Conversation

Cooldude2606
Copy link
Contributor

Prevents circular resolve calls and avoids potential stack overflows by tracking all resolving object-node pairs in a hash table. Solution suggested by @tomlau10

Fixes #3246

@CppCXY CppCXY requested a review from Copilot August 7, 2025 07:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a stack overflow issue that occurs when resolving function return values in circular type dependencies. The solution prevents infinite recursion by tracking resolving object-node pairs in a hash table.

  • Adds circular dependency detection to the resolve function in script/vm/sign.lua
  • Includes a regression test case for circular function type aliases
  • Updates the changelog to document the fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
script/vm/sign.lua Implements circular resolve call detection using a hash table to prevent stack overflow
test/type_inference/common.lua Adds test case with circular function type aliases to verify the fix
changelog.md Documents the stack overflow fix in the changelog

if resolving[resolveHash] then
return -- prevent circular resolve calls
end
resolving[resolveHash] = true
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolving hash entry is never cleared after the resolve call completes, which could lead to memory accumulation and potentially incorrect behavior if the same object-node pair needs to be resolved again in a different context. Consider clearing the entry after the resolve call finishes or using a different approach like a call stack tracker.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the structure of this function, it would be required to maintain 6 cleanup points for each of the 6 returns. This reduces the maintainability in favour of techical correctness. But as it is shown by the passing of all tests, there is no incorrect behaviour by not performing the cleanup; additionally, memory accumulation is minimal as each entry in the hash table is small and the table is gc'd after resolution is complete. Therefore, I do not see a reason to perform manual cleanup despite it's techical correctness, although happy to add it if others disagree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the variable name resolving is a bit misleading 😕
actually it acts like a visited hash table to store all pairs that have triggered a resolve()
=> no need to resolve the same pair more than once (which is my original intention)

maybe we should pick a better variable name? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does read more clearly, I'll make that update 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice naming, much better than mark I usually using

@sumneko sumneko merged commit 24b9faa into LuaLS:master Aug 7, 2025
11 checks passed
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.

Stack overflow while attempting to resolve function return value
3 participants