@@ -857,6 +857,57 @@ TEST(ruby_module) {
857857 PASS();
858858}
859859
860+ /* A Ruby `Const.new` call is rewritten to name the CONSTANT, not the method:
861+ * the constructor body lives in `initialize`, so the call should link the class
862+ * like every other language's `new T()`. The rewrite fired only for bare
863+ * `constant` receivers, so a scope-resolved receiver kept the whole call text
864+ * as its callee ("Admin::User.new"), which resolves to nothing and cannot join
865+ * the Ruby LSP's constructor rows, whose callee is the class QN.
866+ *
867+ * Both spellings must land on the bare constant path; a retained ".new" suffix
868+ * is the bug's signature. */
869+ TEST(ruby_constructor_callee_is_constant_path) {
870+ CBMFileResult *r = extract("module Admin\n class User\n end\nend\n"
871+ "class Widget\nend\n"
872+ "class Maker\n"
873+ " def build\n"
874+ " Admin::User.new\n"
875+ " Widget.new\n"
876+ " end\n"
877+ "end\n",
878+ CBM_LANG_RUBY, "t", "maker.rb");
879+ ASSERT_NOT_NULL(r);
880+ ASSERT_FALSE(r->has_error);
881+
882+ int scoped = 0, bare = 0, kept_new = 0;
883+ for (int i = 0; i < r->calls.count; i++) {
884+ const char *callee = r->calls.items[i].callee_name;
885+ if (strcmp(callee, "Admin::User") == 0)
886+ scoped = 1;
887+ if (strcmp(callee, "Widget") == 0)
888+ bare = 1;
889+ /* Either failure mode: the method name survived on its own, or the
890+ * whole `Recv.new` expression did. */
891+ size_t n = strlen(callee);
892+ if (strcmp(callee, "new") == 0 || (n >= 4 && strcmp(callee + n - 4, ".new") == 0))
893+ kept_new = 1;
894+ }
895+ if (!scoped || !bare || kept_new) {
896+ printf(" ruby callees (%d):\n", r->calls.count);
897+ for (int i = 0; i < r->calls.count; i++)
898+ printf(" '%s'\n", r->calls.items[i].callee_name);
899+ }
900+ /* Scope-resolved receiver reduces to the constant path; its bare leaf is
901+ * what resolution joins on. */
902+ ASSERT(scoped);
903+ /* Bare receiver: pre-existing behaviour, guarded against regression. */
904+ ASSERT(bare);
905+ ASSERT_FALSE(kept_new);
906+
907+ cbm_free_result(r);
908+ PASS();
909+ }
910+
860911/* --- C# --- */
861912TEST(csharp_class) {
862913 CBMFileResult *r = extract("namespace App { public class Service { public void Run() {} public "
@@ -13493,6 +13544,7 @@ SUITE(extraction) {
1349313544 RUN_TEST(php_function);
1349413545 RUN_TEST(ruby_class);
1349513546 RUN_TEST(ruby_module);
13547+ RUN_TEST(ruby_constructor_callee_is_constant_path);
1349613548 RUN_TEST(csharp_class);
1349713549 RUN_TEST(csharp_interface);
1349813550 RUN_TEST(csharp_extension_block_members);
0 commit comments