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:
2026-10-04 14:04:01 +03:00
parent f071684aec
commit 7f3f22e853
2 changed files with 27 additions and 7 deletions

View File

@@ -109,7 +109,15 @@
(test-assert "and so is a receiver with no type to dispatch on"
(reports? "(fn f () void (var n int 1) (.get n))" "no such method on"))
(test-assert "an address cannot be taken of a call"
(reports? (ops-src "(.length (mk))") "receiver is not an lvalue")))
(reports? (ops-src "(.length (mk))") "receiver is not an lvalue"))
;; the inner call has to be typed to find the outer one's receiver
(test-assert "a method call can be another's receiver"
(emits? (string-append
"(record w ((x int)))"
"(ops w (fn twice ((a w)) w (return a))"
" (fn get ((a w)) int (return (. a x))))"
"(fn f () int (var a w #(w : 1)) (return (.get (.twice a))))")
"wːget(wːtwice(a))")))
;; A sum is the tag enum, a payload struct per variant that carries
;; fields, the record holding both, and a constructor each.