refuse a field a struct declared here does not have

The path was walked on and handed to cc, which named the missing field
only in C; a test leaned on a struct s an earlier test had declared.
This commit is contained in:
2026-10-15 14:47:12 +03:00
parent 2279c371f2
commit f84010eda8
2 changed files with 22 additions and 3 deletions

View File

@@ -1116,7 +1116,8 @@
;;; A type we cannot work out is read as a value, which is what the
;;; 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.
;;; only C knows -- (. font handle x) warns of (. font handle), not
;;; font. A field a struct declared here lacks is an error.
(define (walk-member-path form env)
(let ((base (second form)))
(let step ((expr (walk-operand base env))
@@ -1125,7 +1126,10 @@
(told? #f))
(if (null? fields)
(copy-form-source! form expr)
(let ((target (pointer-target type)))
(let* ((target (pointer-target type))
(known (type-fields (or target type))))
(when (and (pair? known) (not (assq (field-name (car fields)) known)))
(sex-error form "no field of this name in" (or target type) (car fields)))
(unless (or type told?)
(let ((walked (drop-right (cddr form) (length fields))))
(sex-warning form "cannot type this; `.' reads it as a value"
@@ -1135,6 +1139,12 @@
(cdr fields)
(or told? (not type))))))))
;;; A field of a path, indexed or not: xs, [xs 0] -> xs
(define (field-name field)
(if (and (pair? field) (eq? '¤ (car field)) (pair? (cdr field)))
(second field)
field))
(define (lvalue? expr)
(cond ((symbol? expr) #t)
((vector? expr) #t) ; a compound literal is one