1
0
forked from alex-eg/sex

see a pointer through a typedef of one

Only a written (* T) was a pointer, so with (typedef pt-ref (* pt)) a
path read q as a value and a method found no type to dispatch on.
This commit is contained in:
2026-10-17 17:35:47 +03:00
parent 04c3267bfe
commit 42c76d07e6
2 changed files with 21 additions and 4 deletions

View File

@@ -4,6 +4,14 @@
(import srfi-13)
;;; A record reached through a typedef of a pointer to it
(define pt-ref-src
(string-append
"(record pt ((x int)))"
"(ops pt (fn get ((self (* pt))) int (return (. self x))))"
"(typedef pt-ref (* pt))"
"(fn f ((q pt-ref)) int (return (+ (. q x) (. (* q) x) (.get q))))"))
;;; Paths through arrays of a struct and of pointers to one
(define poly-src
(string-append
@@ -989,6 +997,14 @@
(emits? poly-src "q->pp[0]->y"))
(test-assert "and every index of one is written"
(emits? poly-src "q->grid[1][2].x"))
;; 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"
(emits? pt-ref-src "q->x"))
(test-assert "dereferences to what it points at"
(not (warns? pt-ref-src "cannot type")))
(test-assert "and calls its target's methods"
(emits? pt-ref-src "ptːget(q)"))
(test-assert "a pointer reads with an arrow"
(emits? (in-line "(= (. pp x) 1)") "pp->x = 1"))
;; each step asks the type in hand, so one path may be both