name what a member path could not type

Past a typed base, it is a field of a struct only C knows that has no
type, and the warning named the base anyway: `font' for what was
(. font handle), with font declared on the line before.

Fixes #41.
This commit is contained in:
2026-10-09 17:28:20 +03:00
parent 062cb18c60
commit 42fe477e35
2 changed files with 16 additions and 2 deletions

View File

@@ -1081,11 +1081,14 @@
;;; (. l a x) l : (struct line), l.a : (* struct point) -> l.a->x
;;;
;;; A type we cannot work out is read as a value, which is what the
;;; path would have meant before any of this.
;;; path would have meant before any of this. The warning names what
;;; could not be typed: the base, or the path up to a field of a struct
;;; only C knows -- (. font handle), not font.
(define (walk-member-path form env)
(let ((base (second form)))
(let step ((expr (walk-operand base env))
(type (expression-type base env))
(read (list)) ; the fields walked, reversed
(fields (cddr form))
(told? #f))
(if (null? fields)
@@ -1093,9 +1096,12 @@
(let ((target (pointer-target type)))
(unless (or type told?)
(sex-warning form "cannot type this; `.' reads it as a value"
base))
(if (null? read)
base
`(|.| ,base ,@(reverse read)))))
(step (list (if target '%-> 'dot-access) expr (car fields))
(field-type (or target type) (car fields))
(cons (car fields) read)
(cdr fields)
(or told? (not type))))))))

View File

@@ -833,6 +833,14 @@ whitespace aside, THEN?"
(emits? (in-line "(= (. (guess) x) 1)") "guess().x = 1"))
(test-assert "and said so"
(warns? (in-line "(= (. (guess) x) 1)") "cannot type this"))
;; Past a typed base it is a field that cannot be typed -- one of a
;; struct only C knows -- and the warning named the base regardless
(test-assert "naming the path read so far"
(warns? (in-fn "(var t (* struct tm) 0) (= (. t a b) 1)")
"as a value (. t a)\n"))
(test-assert "which one step through it does not need"
(not (warns? (in-fn "(var t (* struct tm) 0) (= (. t a) 1)")
"cannot type")))
;; the arrow is `%->' and nothing else writes one, so a bare `->'
;; is an ordinary head -- a threading macro that nobody imported,
;; and a call like any other unknown