Skip to content

fix(semantic): stop following circular type declarations#1051

Merged
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
lewis6991:split/semantic-decl-cycle-guards
Apr 29, 2026
Merged

fix(semantic): stop following circular type declarations#1051
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
lewis6991:split/semantic-decl-cycle-guards

Conversation

@lewis6991
Copy link
Copy Markdown
Collaborator

When aliases or class parents point back to themselves, stop using that
loop for normal analysis instead of trying to expand it forever.

Pure alias loops now become any, and circular class parents are still
visible to the existing diagnostic.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements cycle detection for Lua type aliases and class inheritance to prevent infinite recursion during type resolution. It introduces logic to collapse cyclic aliases to 'Any' and filters cyclic edges when retrieving super types. Review feedback identifies a potential performance bottleneck in the iterative cycle check, suggests exposing a helper function for broader use, and points out that the diagnostic checker currently misses cycles involving generic base classes.

Comment thread crates/emmylua_code_analysis/src/db_index/type/mod.rs Outdated
Comment thread crates/emmylua_code_analysis/src/db_index/type/mod.rs Outdated
@lewis6991 lewis6991 force-pushed the split/semantic-decl-cycle-guards branch from add63a5 to 2b9e9d8 Compare April 27, 2026 15:41
@lewis6991
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces logic to detect and handle circular dependencies in Lua type aliases and class inheritance. It implements cycle detection in analyze_alias to collapse recursive aliases to LuaType::Any and filters cyclic super-type edges within the type index to prevent infinite recursion during type resolution. The review feedback correctly identifies potential logic errors in the new test cases, where assertions use negation (!) despite the test names and code structure suggesting that diagnostics for circularity should be reported.

@lewis6991 lewis6991 force-pushed the split/semantic-decl-cycle-guards branch from 2b9e9d8 to 86128b0 Compare April 27, 2026 15:52
Some(())
}

fn alias_origin_reaches(db: &crate::DbIndex, origin: &LuaType, target_id: &LuaTypeDeclId) -> bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove crate::

When aliases or class parents point back to themselves, stop using that
loop for normal analysis instead of trying to expand it forever.

Pure alias loops now become any, and circular class parents are still
visible to the existing diagnostic.
@lewis6991 lewis6991 force-pushed the split/semantic-decl-cycle-guards branch from 86128b0 to c87ca5f Compare April 29, 2026 08:36
@CppCXY CppCXY merged commit 192e3d7 into EmmyLuaLs:main Apr 29, 2026
16 checks passed
@lewis6991 lewis6991 deleted the split/semantic-decl-cycle-guards branch April 29, 2026 09:08
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