type a call by the type of what it calls

Only a function's name was asked what it returns, so a call through a
local or a field holding a pointer had no type, a local named like a
function took the function's, and a closure's call helper, which
nothing registered, left _ nothing to read.
This commit is contained in:
2026-10-19 13:38:30 +03:00
parent b203e3e687
commit 904c832384
2 changed files with 38 additions and 1 deletions

View File

@@ -1403,7 +1403,19 @@
(cond
((method-head? (car expr)) (method-call-type expr env))
((receiver-closure-type (car expr) env) => third)
(else (and (symbol? (car expr)) (get-return-type (car expr))))))))))
;; a function's name, unless a local hides it
((and (symbol? (car expr))
(not (lookup-name env (car expr)))
(get-return-type (car expr)))
=> identity)
;; a pointer to one: a local, a parameter, a field, a call's result
(else (function-return (expression-type (car expr) env)))))))))
;;; (fn ((int)) int) -> int, and through a typedef of one
(define (function-return type)
(cond ((and (pair? type) (eq? (car type) 'fn) (= 3 (length type))) (third type))
((and (symbol? type) (get-underlying-type type)) => function-return)
(else #f)))
;;; (.length-sq (.sub a b)) types the inner call to find the outer
;;; one's receiver, so a method call has to answer like any other
@@ -1838,6 +1850,12 @@
(unwrap-type arg)))
(second type)
(iota (length (second type))))))
;; what it returns, for `_' to read: it goes out as written, and
;; nothing else registers it
(add-name-type! helper
`(fn (((struct ,closure))
,@(map (lambda (p) (list (second p))) params))
,returns))
(unless (hash-table-ref/default +closure-calls+ helper #f)
(hash-table-set! +closure-calls+ helper #t)
(let ((call `((dot-access ƛc code)