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:
10
semen.scm
10
semen.scm
@@ -1113,11 +1113,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)
|
||||
@@ -1125,9 +1128,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))))))))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user