forked from alex-eg/sex
type a method call, so one can be another's receiver
expression-type knew nothing about a .method head, so the receiver of (.length-sq (.sub a b)) had no type and the outer call could not resolve. Vector arithmetic is nothing but nested calls like that one.
This commit is contained in:
24
semen.scm
24
semen.scm
@@ -970,13 +970,25 @@
|
||||
;; ...and an increment is the operand unpromoted:
|
||||
;; (++ c), c : char -> char
|
||||
((++ --) (expression-type (second expr) env))
|
||||
;; otherwise a call: a closure answers with its own return type,
|
||||
;; anything else with what its signature says
|
||||
;; otherwise a call: a method answers for the name it resolves
|
||||
;; to, a closure with its own return type, anything else with
|
||||
;; what its signature says
|
||||
(else
|
||||
(let ((closure (receiver-closure-type (car expr) env)))
|
||||
(if closure
|
||||
(third closure)
|
||||
(and (symbol? (car expr)) (get-return-type (car expr))))))))))
|
||||
(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))))))))))
|
||||
|
||||
;;; (.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
|
||||
(define (method-call-type expr env)
|
||||
(and (pair? (cdr expr))
|
||||
(let* ((written (expression-type (second expr) env))
|
||||
(target (pointer-target written))
|
||||
(key (ops-key (or target written))))
|
||||
(and key
|
||||
(let ((method (get-method key (method-head-name (car expr)))))
|
||||
(and method (get-return-type method)))))))
|
||||
|
||||
;;; C's usual arithmetic conversions, far enough to answer `_':
|
||||
;;;
|
||||
|
||||
Reference in New Issue
Block a user