Skip to content

Conversation

@chrapkowski-sg
Copy link
Contributor

@chrapkowski-sg chrapkowski-sg commented Feb 3, 2026

CU-2372 Removes the synthetic serialize() definition generation.

Motivation

When users click "Find References" on a T::Enum class name in Sourcegraph, the UI sometimes shows references to the serialize() method instead of references to the class itself.

This happens because scip-ruby emits two definitions at the exact same source location:

  1. The class definition (e.g., Foo#)
  2. The synthetic serialize() method (e.g., Foo#serialize().)

When the Sourcegraph frontend queries for the symbol at a position and finds multiple overlapping definitions, it may pick the wrong one, causing Find References to return incorrect results.

Now only definition for the class is provided:

Problem

The synthetic serialize() method definition was emitted at the T::Enum class
declaration location, causing overlapping definitions with the class itself.
This broke Find References in Sourcegraph UI, which would pick up serialize
references instead of class references.

Before

class Foo < T::Enum
#     ^^^ definition [..] Foo#
#     ^^^ definition [..] Foo#serialize().
#           ^ reference [..] T#
#              ^^^^ reference [..] Module#public().
#              ^^^^ reference [..] String#
#              ^^^^ reference [..] T#Enum#

After

class Foo < T::Enum
#     ^^^ definition [..] Foo#
#           ^ reference [..] T#
#              ^^^^ reference [..] T#Enum#

Test plan

See included automated tests.

@chrapkowski-sg
Copy link
Contributor Author

chrapkowski-sg commented Feb 3, 2026

@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from f978d5f to 63c20ad Compare February 3, 2026 18:37
@chrapkowski-sg chrapkowski-sg requested a review from jupblb February 3, 2026 18:46
@chrapkowski-sg chrapkowski-sg changed the base branch from scip-ruby/master to ci-fix February 3, 2026 19:02
@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from 63c20ad to e870522 Compare February 3, 2026 19:02
@chrapkowski-sg chrapkowski-sg marked this pull request as ready for review February 3, 2026 19:02
@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from e870522 to 2391c4c Compare February 3, 2026 19:04
@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from 2391c4c to 15e48fc Compare February 3, 2026 19:14
Base automatically changed from ci-fix to scip-ruby/master February 3, 2026 22:11
@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from 15e48fc to d7969ce Compare February 3, 2026 22:52
Copy link
Member

@jupblb jupblb left a comment

Choose a reason for hiding this comment

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

Left two comments. Looks ok.

@@ -0,0 +1,59 @@
From f360b43dedfb38b386180fe5847a77b90e823faa Mon Sep 17 00:00:00 2001
Copy link
Member

Choose a reason for hiding this comment

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

What is this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

accidentally added

}
}
}
if (core::isa_type<core::ClassType>(serializeReturnType) && !serializeReturnType.isUntyped() &&
Copy link
Member

Choose a reason for hiding this comment

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

Removing this is a serious deviation from the upstream:

scip-ruby/rewriter/TEnum.cc

Lines 241 to 257 in 0a7b175

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, 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));
}

This is not bad but something worth noting. I hope this doesn't break anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to track this in case of rebases. We have this commit including PR and reasons why this has been removed

…ping 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 <amp@ampcode.com>
@chrapkowski-sg chrapkowski-sg force-pushed the fix-avoid-overlapping-definition branch from d7969ce to a84476a Compare February 4, 2026 18:25
@chrapkowski-sg chrapkowski-sg merged commit 0584803 into scip-ruby/master Feb 4, 2026
5 checks passed
@chrapkowski-sg chrapkowski-sg deleted the fix-avoid-overlapping-definition branch February 4, 2026 18:34
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.

3 participants