Skip to content

Conversation

@pkondzior
Copy link
Contributor

Motivation

Closes #3798

Following code snipper is going to cause StackLevelError and will kill RubyLSP process

Implementation

ruby-lsp is trying to create ConstantAlias from UnresolvedConstantAlias during constant resolution, I am checking if the target matches entry in cases when unresolved entry is same as target entry we should bail out from resolution because thats the same unresolved entry.

Automated Tests

I've created RubyIndexer::ConstantTest#test_self_referential_constant_alias that is giving coverage for this case

Manual Tests

  1. Bootstrap VS Code ruby-lsp from this branch
  2. Paste following code into editor
module RealClass
  CONSTANT = {}
end

module Foo
  SomeClass = ::SomeClass
  RealClass = ::RealClass

  UNRESOLVED = SomeClass::CONSTANT
  CONSTANT = RealClass::CONSTANT
end


RealClass
Foo::UNRESOLVED
  1. Working on the file should not cause any errors on Ruby LSP in the output

@pkondzior pkondzior marked this pull request as ready for review October 27, 2025 11:25
@graphite-app
Copy link

graphite-app bot commented Oct 27, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I believe the fix is the right way to go, but let's make sure the test prevents us from regressing on this

@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Oct 27, 2025
@pkondzior pkondzior requested a review from vinistock October 28, 2025 11:59
@pkondzior pkondzior force-pushed the fix-stack-level-error-on-self-referential-alias branch from c641e15 to 83a3905 Compare October 28, 2025 11:59
@pkondzior pkondzior force-pushed the fix-stack-level-error-on-self-referential-alias branch from 83a3905 to f8e5153 Compare October 28, 2025 12:01
@vinistock vinistock merged commit 957de68 into Shopify:main Oct 28, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack level too deep on self referential constant alias

3 participants