forked from alex-eg/sex
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:
20
semen.scm
20
semen.scm
@@ -1392,7 +1392,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
|
||||
@@ -1827,6 +1839,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)
|
||||
|
||||
Reference in New Issue
Block a user