From 79d9860fc18474ef31f87e6809a3180bbfa805cd Mon Sep 17 00:00:00 2001 From: alex-eg Date: Fri, 9 Oct 2026 17:28:20 +0300 Subject: [PATCH] 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. --- semen.scm | 10 ++++++++-- tests/codegen.scm | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/semen.scm b/semen.scm index 001e37d..783b2d8 100644 --- a/semen.scm +++ b/semen.scm @@ -930,11 +930,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-statement base env)) (type (expression-type base env)) + (read (list)) ; the fields walked, reversed (fields (cddr form)) (told? #f)) (if (null? fields) @@ -942,9 +945,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)))))))) diff --git a/tests/codegen.scm b/tests/codegen.scm index 46a730c..2e8ecca 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -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