From 8535d74aa376d85a5a199f596ed0926eb991507a Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 15:02:51 +0330 Subject: lsp test: block-end borrow message and related info --- tests/drivers/borrow_diag_test.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/drivers/borrow_diag_test.js') diff --git a/tests/drivers/borrow_diag_test.js b/tests/drivers/borrow_diag_test.js index 93a7561..027b978 100644 --- a/tests/drivers/borrow_diag_test.js +++ b/tests/drivers/borrow_diag_test.js @@ -70,4 +70,13 @@ assert.strictEqual(d.relatedInformation[0].message, 'owner t was freed here'); text = 'include rt;\nchar* first(char* a, char* b) borrows a;\nchar* first(char* a, char* b) { return b; }\nfn main() { return 0; }\n'; d = same(text, 'borrows clause'); assert.match(d.message, /returns a borrow of b/); +// a borrow that outlives the block its owner was freed at the end of +text = 'include rt;\nstruct node { int v; node* next; };\nfn main() {\n\tnode* second;\n\t{\n\t\tnode* head = rt.new(node);\n\t\thead.next = rt.new(node);\n\t\tsecond = head.next;\n\t}\n\treturn second.v;\n}\n'; +d = same(text, 'block end'); +assert.match(d.message, /^second: borrows from head, which was freed at the end of its block \(line 9\)$/); +assert.deepStrictEqual(d.range.start, at(text, 'second.v'), 'the range is the conflicting use'); +assert.ok(d.relatedInformation && d.relatedInformation.length === 2, JSON.stringify(d)); +assert.strictEqual(d.relatedInformation[0].message, 'owner head was freed at the end of this block'); +assert.strictEqual(d.relatedInformation[1].message, 'owner head is declared here'); +assert.deepStrictEqual(d.relatedInformation[1].location.range.start, at(text, 'head =')); console.log(`ok borrow diagnostics: ${checks} cases match zy, with ranges and related owner places`); -- cgit v1.2.3