aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 15:02:51 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 15:02:51 +0330
commit8535d74aa376d85a5a199f596ed0926eb991507a (patch)
tree211efb9644be6607d227fec7fb8814f9f149b5ff
parenttests: alias_scope expects the block-end message; plain_return now covers a f... (diff)
lsp test: block-end borrow message and related info
-rw-r--r--tests/drivers/borrow_diag_test.js9
1 files changed, 9 insertions, 0 deletions
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`);