@@ -238,11 +238,22 @@ void TEnum::run(core::MutableContext ctx, ast::ClassDef *klass) {
238238 }
239239 }
240240 }
241- // NOTE: We intentionally skip generating the synthetic serialize() method definition here.
242- // T::Enum provides serialize() but emitting a definition at the class declaration location
243- // causes overlapping definitions with the class itself, which breaks Find References in
244- // Sourcegraph UI. Since serialize() is a Sorbet stdlib method (not user-defined), omitting
245- // the definition is acceptable - users can still navigate via the class inheritance.
246- (void )serializeReturnType; // Silence unused variable warning
241+ if (core::isa_type<core::ClassType>(serializeReturnType) && !serializeReturnType.isUntyped () &&
242+ !serializeReturnType.isBottom ()) {
243+ auto serializeReturnTypeClass = core::cast_type_nonnull<core::ClassType>(serializeReturnType);
244+ ast::ExpressionPtr return_type_ast = ast::MK::Constant (klass->declLoc , serializeReturnTypeClass.symbol );
245+ auto sig = ast::MK::Sig0 (klass->declLoc , std::move (return_type_ast));
246+ auto method = ast::MK::SyntheticMethod0 (klass->loc , klass->declLoc , klass->name .loc (), core::Names::serialize (),
247+ ast::MK::RaiseTypedUnimplemented (klass->declLoc ));
248+ ast::Send::ARGS_store nargs;
249+ ast::Send::Flags flags;
250+ flags.isPrivateOk = true ;
251+ auto visibility = ast::MK::Send (klass->declLoc , ast::MK::Self (klass->declLoc ), core::Names::public_ (),
252+ klass->declLoc , 0 , std::move (nargs), flags);
253+
254+ klass->rhs .emplace_back (std::move (visibility));
255+ klass->rhs .emplace_back (std::move (sig));
256+ klass->rhs .emplace_back (std::move (method));
257+ }
247258}
248259}; // namespace sorbet::rewriter
0 commit comments