read a member path and a receiver through a pointer chain

A pointer to a pointer has no fields, so (. pp x) has one meaning, and
it came out pp->x; it is (*pp)->x, and a method receiver alike.
This commit is contained in:
2026-10-19 14:48:43 +03:00
parent e940f2d2f1
commit 25aa03ac77
2 changed files with 40 additions and 9 deletions

View File

@@ -1318,6 +1318,22 @@ whitespace aside, THEN?"
(emits? poly-src "q->pp[0]->y"))
(test-assert "and every index of one is written"
(emits? poly-src "q->grid[1][2].x"))
;; a pointer to a pointer has no fields, so a path reads through
;; every pointer to the aggregate, where it wrote pp->x
(test-assert "a pointer to a pointer is read through"
(emits? "(struct pt ((x int))) (fn f ((pp (* * struct pt))) int (return (. pp x)))"
"(*pp)->x"))
(test-assert "however many there are"
(emits? "(struct pt ((x int))) (fn f ((p3 (* * * struct pt))) int (return (. p3 x)))"
"(*(*p3))->x"))
(test-assert "and typed through"
(emits? "(struct pt ((x float))) (fn f ((pp (* * struct pt))) void (var v _ (. pp x)))"
"float v = (*pp)->x"))
(test-assert "a method's receiver too"
(emits? (string-append "(record pt ((x int)))"
"(ops pt (fn get ((self (* pt))) int (return (. self x))))"
"(fn f ((pp (* * pt))) int (return (.get pp)))")
"ptːget(*pp)"))
;; only a written (* T) was a pointer, so a typedef of one read as a
;; value, and a method could not find its receiver's type
(test-assert "a typedef of a pointer reads with an arrow"