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. */
169176static int assert_lsp_strategy (const char * filename , const char * src ,
170177 const char * strategy ) {
@@ -297,6 +304,22 @@ static const RFile kTsImport[] = {
297304 "function caller(v: number): number { return helper(v); }\n" },
298305};
299306
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.
309+ */
310+ static const RFile kTsInferredImportedMethod [] = {
311+ {"store.ts" ,
312+ "export class WidgetStore {\n"
313+ " findById(id: string): string { return id; }\n"
314+ "}\n" },
315+ {"service.ts" ,
316+ "import { WidgetStore } from \"./store\";\n"
317+ "const inferred = new WidgetStore();\n"
318+ "function load(id: string): string {\n"
319+ " return inferred.findById(id);\n"
320+ "}\n" },
321+ };
322+
300323/* lsp_ts_jsx — <Comp/> JSX element whose tag is a module-local component
301324 * function (ts_lsp.c:2643-2647). TSX only (jsx_mode); the tag's first letter is
302325 * uppercase so it is NOT treated as an intrinsic HTML element; it resolves via
@@ -370,6 +393,14 @@ TEST(repro_lsp_ts_import) {
370393 "lsp_ts_import" );
371394}
372395
396+ TEST (repro_lsp_ts_inferred_import_module_receiver ) {
397+ return assert_lsp_strategy_files_expected (
398+ kTsInferredImportedMethod ,
399+ (int )(sizeof (kTsInferredImportedMethod ) /
400+ sizeof (kTsInferredImportedMethod [0 ])),
401+ "lsp_ts_method" , 1 );
402+ }
403+
373404TEST (repro_lsp_ts_jsx ) {
374405 return assert_lsp_strategy ("app.tsx" , kTsxJsx , "lsp_ts_jsx" );
375406}
@@ -403,6 +434,7 @@ SUITE(repro_lsp_ts) {
403434 RUN_TEST (repro_lsp_ts_method );
404435 RUN_TEST (repro_lsp_ts_namespace );
405436 RUN_TEST (repro_lsp_ts_import );
437+ RUN_TEST (repro_lsp_ts_inferred_import_module_receiver );
406438 RUN_TEST (repro_lsp_ts_jsx );
407439 RUN_TEST (repro_lsp_ts_jsx_import );
408440 RUN_TEST (repro_lsp_ts_default );
0 commit comments