type an indexed step of a member path
(. q [pts 2] y) looked the step up as a field whole, so its type was lost: the next step guessed a value, and through an array of pointers wrote . for ->.
This commit is contained in:
@@ -67,6 +67,14 @@ whitespace aside, THEN?"
|
||||
(let ((next (string-skip c char-whitespace? (+ at (string-length first)))))
|
||||
(and next (string-prefix? then (substring c next)))))))
|
||||
|
||||
;;; Paths through arrays of a struct and of pointers to one
|
||||
(define poly-src
|
||||
(string-append
|
||||
"(struct pt ((x int) (y int)))"
|
||||
"(struct poly ((pts [(struct pt) 4]) (pp [* struct pt 4]) (grid [(struct pt) 2 3])))"
|
||||
"(fn f ((q (* struct poly))) int"
|
||||
" (return (+ (. q [pts 2] y) (. q [pp 0] y) (. q [grid 1 2] x))))"))
|
||||
|
||||
(define (in-fn body)
|
||||
(string-append "(fn f ((a int) (b int)) void " body ")"))
|
||||
|
||||
@@ -1036,6 +1044,16 @@ whitespace aside, THEN?"
|
||||
(test-group "member access"
|
||||
(test-assert "a value reads with a dot"
|
||||
(emits? (in-line "(= (. p x) 1)") "p.x = 1"))
|
||||
;; an indexed step was looked up as a field whole, so its type was
|
||||
;; lost and the step after it guessed
|
||||
(test-assert "an indexed step is its field's element"
|
||||
(emits? poly-src "q->pts[2].y"))
|
||||
(test-assert "and says so without a warning"
|
||||
(not (warns? poly-src "cannot type")))
|
||||
(test-assert "so a pointer element is read through"
|
||||
(emits? poly-src "q->pp[0]->y"))
|
||||
(test-assert "and every index of one is written"
|
||||
(emits? poly-src "q->grid[1][2].x"))
|
||||
(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
|
||||
|
||||
Reference in New Issue
Block a user