From 27044fcaaaf8af2a8a47a69eab881eb05707e432 Mon Sep 17 00:00:00 2001 From: Adam Chrapkowski Date: Mon, 2 Feb 2026 18:03:53 +0100 Subject: [PATCH 1/2] fix: avoid overlapping definition for T::Enum synthetic serialize() method --- rewriter/TEnum.cc | 5 ++++- test/scip/testdata/alias.snapshot.rb | 2 +- test/scip/testdata/enum.snapshot.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rewriter/TEnum.cc b/rewriter/TEnum.cc index 8fa0bdd7f..cdc460ae9 100644 --- a/rewriter/TEnum.cc +++ b/rewriter/TEnum.cc @@ -243,7 +243,10 @@ void TEnum::run(core::MutableContext ctx, ast::ClassDef *klass) { auto serializeReturnTypeClass = core::cast_type_nonnull(serializeReturnType); ast::ExpressionPtr return_type_ast = ast::MK::Constant(klass->declLoc, serializeReturnTypeClass.symbol); auto sig = ast::MK::Sig0(klass->declLoc, std::move(return_type_ast)); - auto method = ast::MK::SyntheticMethod0(klass->loc, klass->declLoc, klass->name.loc(), core::Names::serialize(), + // Use zero-length location for the synthetic serialize() method name to avoid + // overlapping with the class name definition. Overlapping definitions cause + // issues in the Sourcegraph UI where Find References picks up the wrong symbol. + auto method = ast::MK::SyntheticMethod0(klass->loc, klass->declLoc, locZero, core::Names::serialize(), ast::MK::RaiseTypedUnimplemented(klass->declLoc)); ast::Send::ARGS_store nargs; ast::Send::Flags flags; diff --git a/test/scip/testdata/alias.snapshot.rb b/test/scip/testdata/alias.snapshot.rb index c1640f11f..f88ee7ef7 100644 --- a/test/scip/testdata/alias.snapshot.rb +++ b/test/scip/testdata/alias.snapshot.rb @@ -48,8 +48,8 @@ def myfunction(myparam) class X < T::Enum # ^ definition [..] X# -# ^ definition [..] X#serialize(). # ^ reference [..] T# +# ^^^^ definition [..] X#serialize(). # ^^^^ reference [..] Module#public(). # ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# diff --git a/test/scip/testdata/enum.snapshot.rb b/test/scip/testdata/enum.snapshot.rb index 38076423c..a191952b5 100644 --- a/test/scip/testdata/enum.snapshot.rb +++ b/test/scip/testdata/enum.snapshot.rb @@ -2,8 +2,8 @@ class X < T::Enum # ^ definition [..] X# -# ^ definition [..] X#serialize(). # ^ reference [..] T# +# ^^^^ definition [..] X#serialize(). # ^^^^ reference [..] Module#public(). # ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# From a84476abeb6332203236cec6510cdcd998b72e41 Mon Sep 17 00:00:00 2001 From: Adam Chrapkowski Date: Tue, 3 Feb 2026 19:31:34 +0100 Subject: [PATCH 2/2] fix: remove T::Enum synthetic serialize() definition to avoid overlapping symbols ## Problem The synthetic serialize() method definition was emitted at the same location as the class name, causing two overlapping definitions. This broke Find References in Sourcegraph UI, which would pick up serialize references instead of class references. ## Solution Remove the synthetic serialize() method generation entirely. Since serialize() is a Sorbet stdlib method (not user-defined), omitting the definition is acceptable - users can still navigate via the class inheritance chain. ## Before ```ruby class Foo < T::Enum # ^^^ definition [..] Foo# # ^^^ definition [..] Foo#serialize(). # ^ reference [..] T# # ^^^^ reference [..] Module#public(). # ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# ``` ## After ```ruby class Foo < T::Enum # ^^^ definition [..] Foo# # ^ reference [..] T# # ^^^^ reference [..] T#Enum# ``` Fixes CU-2372 Amp-Thread-ID: https://ampcode.com/threads/T-019c2423-1e50-751d-9ebb-17cbf138874d Co-authored-by: Amp --- rewriter/TEnum.cc | 26 ++++++-------------------- test/scip/testdata/alias.snapshot.rb | 5 +---- test/scip/testdata/enum.snapshot.rb | 5 +---- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/rewriter/TEnum.cc b/rewriter/TEnum.cc index cdc460ae9..68a7adda0 100644 --- a/rewriter/TEnum.cc +++ b/rewriter/TEnum.cc @@ -238,25 +238,11 @@ void TEnum::run(core::MutableContext ctx, ast::ClassDef *klass) { } } } - if (core::isa_type(serializeReturnType) && !serializeReturnType.isUntyped() && - !serializeReturnType.isBottom()) { - auto serializeReturnTypeClass = core::cast_type_nonnull(serializeReturnType); - ast::ExpressionPtr return_type_ast = ast::MK::Constant(klass->declLoc, serializeReturnTypeClass.symbol); - auto sig = ast::MK::Sig0(klass->declLoc, std::move(return_type_ast)); - // Use zero-length location for the synthetic serialize() method name to avoid - // overlapping with the class name definition. Overlapping definitions cause - // issues in the Sourcegraph UI where Find References picks up the wrong symbol. - auto method = ast::MK::SyntheticMethod0(klass->loc, klass->declLoc, locZero, core::Names::serialize(), - ast::MK::RaiseTypedUnimplemented(klass->declLoc)); - ast::Send::ARGS_store nargs; - ast::Send::Flags flags; - flags.isPrivateOk = true; - auto visibility = ast::MK::Send(klass->declLoc, ast::MK::Self(klass->declLoc), core::Names::public_(), - klass->declLoc, 0, std::move(nargs), flags); - - klass->rhs.emplace_back(std::move(visibility)); - klass->rhs.emplace_back(std::move(sig)); - klass->rhs.emplace_back(std::move(method)); - } + // NOTE: We intentionally skip generating the synthetic serialize() method definition here. + // T::Enum provides serialize() but emitting a definition at the class declaration location + // causes overlapping definitions with the class itself, which breaks Find References in + // Sourcegraph UI. Since serialize() is a Sorbet stdlib method (not user-defined), omitting + // the definition is acceptable - users can still navigate via the class inheritance. + (void)serializeReturnType; // Silence unused variable warning } }; // namespace sorbet::rewriter diff --git a/test/scip/testdata/alias.snapshot.rb b/test/scip/testdata/alias.snapshot.rb index f88ee7ef7..9a2c75f2e 100644 --- a/test/scip/testdata/alias.snapshot.rb +++ b/test/scip/testdata/alias.snapshot.rb @@ -49,9 +49,6 @@ def myfunction(myparam) class X < T::Enum # ^ definition [..] X# # ^ reference [..] T# -# ^^^^ definition [..] X#serialize(). -# ^^^^ reference [..] Module#public(). -# ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# enums do A = new("A") @@ -70,7 +67,7 @@ class X < T::Enum # ^^^ definition [..] X#All. # ^ reference [..] X#A. # ^ reference [..] X#B. -# ^^^^^^^^ definition local 4$119448696 +# ^^^^^^^^ definition local 3$119448696 # ^ reference [..] X# end diff --git a/test/scip/testdata/enum.snapshot.rb b/test/scip/testdata/enum.snapshot.rb index a191952b5..6721ab146 100644 --- a/test/scip/testdata/enum.snapshot.rb +++ b/test/scip/testdata/enum.snapshot.rb @@ -3,9 +3,6 @@ class X < T::Enum # ^ definition [..] X# # ^ reference [..] T# -# ^^^^ definition [..] X#serialize(). -# ^^^^ reference [..] Module#public(). -# ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# enums do A = new("A") @@ -24,7 +21,7 @@ class X < T::Enum # ^^^ definition [..] X#All. # ^ reference [..] X#A. # ^ reference [..] X#B. -# ^^^^^^^^ definition local 4$119448696 +# ^^^^^^^^ definition local 3$119448696 # ^ reference [..] X# end