Skip to content

Commit ec56ea8

Browse files
test: cover the return-type walk past the old stack cap
The first commit converted three walks in ts_lsp.c but tested only two of them. infer_return_type_from_body was changed without a test of its own. tslsp_stress_return_past_stack_cap makes the same claim as the existing tslsp_return_inferred_local, with the return placed after 300 statements — more than the 256 slots the old fixed array held, so the walk used to stop before reaching it and answer "unknown return type". Without the fix the suite is 303 passed, 2 failed, the second failure being this test. With it, 305 passed. Signed-off-by: Joshua Richter <jrichter5781@gmail.com>
1 parent b974adf commit ec56ea8

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎tests/test_ts_lsp.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,6 +2846,35 @@ TEST(tslsp_stress_declarations_past_stack_cap) {
28462846
PASS();
28472847
}
28482848

2849+
TEST(tslsp_stress_return_past_stack_cap) {
2850+
/* infer_return_type_from_body reads the return type out of a body that
2851+
* carries no written one. The return here sits after 300 statements, more
2852+
* than the old fixed cap held, so the walk used to stop before reaching it
2853+
* and answer "unknown return type". */
2854+
enum { BUF_CAP = 64 * 1024 };
2855+
char *buf = (char *)malloc(BUF_CAP);
2856+
if (!buf)
2857+
PASS();
2858+
char *p = buf;
2859+
char *end = buf + BUF_CAP;
2860+
p += snprintf(p, (size_t)(end - p), "class Conn { ping(): void {} }\n");
2861+
p += snprintf(p, (size_t)(end - p), "function makeConn() {\n");
2862+
for (int i = 0; i < 300; i++) {
2863+
p += snprintf(p, (size_t)(end - p), " let a%d = 0;\n", i);
2864+
}
2865+
p += snprintf(p, (size_t)(end - p), " return new Conn();\n}\n");
2866+
p += snprintf(p, (size_t)(end - p), "function go() { const c = makeConn(); c.ping(); }\n");
2867+
*p = '\0';
2868+
2869+
CBMFileResult *r = extract_ts(buf);
2870+
free(buf);
2871+
ASSERT_NOT_NULL(r);
2872+
/* Same claim as tslsp_return_inferred_local, 300 statements deeper. */
2873+
ASSERT_GTE(require_resolved(r, ".go", "ping"), 0);
2874+
cbm_free_result(r);
2875+
PASS();
2876+
}
2877+
28492878
TEST(tslsp_stress_deep_inheritance) {
28502879
/* Chain of 30 classes via extends, leaf method on root. */
28512880
char buf[16 * 1024];
@@ -4595,6 +4624,7 @@ SUITE(ts_lsp) {
45954624
/* Stress tests */
45964625
RUN_TEST(tslsp_stress_many_classes);
45974626
RUN_TEST(tslsp_stress_declarations_past_stack_cap);
4627+
RUN_TEST(tslsp_stress_return_past_stack_cap);
45984628
RUN_TEST(tslsp_stress_deep_inheritance);
45994629
RUN_TEST(tslsp_stress_long_method_chain);
46004630
RUN_TEST(tslsp_stress_megafile_mixed);

0 commit comments

Comments
 (0)