From 4fa40609cc92937018fc057691a8375e2937a1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kie=C5=82bowicz?= Date: Mon, 16 Feb 2026 11:29:22 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20avoid=20overlapping=20definiti?= =?UTF-8?q?on=20for=20T::Enum=20synthetic=20serialize()=20m=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 058480329179874c09ceca5456b93c07b960b0fb. --- rewriter/TEnum.cc | 23 +++++++++++++++++------ test/scip/testdata/alias.snapshot.rb | 5 ++++- test/scip/testdata/enum.snapshot.rb | 5 ++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/rewriter/TEnum.cc b/rewriter/TEnum.cc index 68a7adda0..8fa0bdd7f 100644 --- a/rewriter/TEnum.cc +++ b/rewriter/TEnum.cc @@ -238,11 +238,22 @@ void TEnum::run(core::MutableContext ctx, ast::ClassDef *klass) { } } } - // 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 + 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)); + auto method = ast::MK::SyntheticMethod0(klass->loc, klass->declLoc, klass->name.loc(), 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)); + } } }; // namespace sorbet::rewriter diff --git a/test/scip/testdata/alias.snapshot.rb b/test/scip/testdata/alias.snapshot.rb index 9a2c75f2e..c1640f11f 100644 --- a/test/scip/testdata/alias.snapshot.rb +++ b/test/scip/testdata/alias.snapshot.rb @@ -48,7 +48,10 @@ def myfunction(myparam) class X < T::Enum # ^ definition [..] X# +# ^ definition [..] X#serialize(). # ^ reference [..] T# +# ^^^^ reference [..] Module#public(). +# ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# enums do A = new("A") @@ -67,7 +70,7 @@ class X < T::Enum # ^^^ definition [..] X#All. # ^ reference [..] X#A. # ^ reference [..] X#B. -# ^^^^^^^^ definition local 3$119448696 +# ^^^^^^^^ definition local 4$119448696 # ^ reference [..] X# end diff --git a/test/scip/testdata/enum.snapshot.rb b/test/scip/testdata/enum.snapshot.rb index 6721ab146..38076423c 100644 --- a/test/scip/testdata/enum.snapshot.rb +++ b/test/scip/testdata/enum.snapshot.rb @@ -2,7 +2,10 @@ class X < T::Enum # ^ definition [..] X# +# ^ definition [..] X#serialize(). # ^ reference [..] T# +# ^^^^ reference [..] Module#public(). +# ^^^^ reference [..] String# # ^^^^ reference [..] T#Enum# enums do A = new("A") @@ -21,7 +24,7 @@ class X < T::Enum # ^^^ definition [..] X#All. # ^ reference [..] X#A. # ^ reference [..] X#B. -# ^^^^^^^^ definition local 3$119448696 +# ^^^^^^^^ definition local 4$119448696 # ^ reference [..] X# end