Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions rewriter/TEnum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<core::ClassType>(serializeReturnType) && !serializeReturnType.isUntyped() &&
!serializeReturnType.isBottom()) {
auto serializeReturnTypeClass = core::cast_type_nonnull<core::ClassType>(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
5 changes: 4 additions & 1 deletion test/scip/testdata/alias.snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion test/scip/testdata/enum.snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
Loading