forked from alex-eg/sex
read a spread self as the pointer it is
(self * const v) typed the method's self as `self', so a call passed a value where the method took a pointer, and a spec written one way refused a realization written the other. A const receiver handed to a method taking (* v) is now refused rather than left to cc's warning.
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
"(record vec2 ((x float) (y float)))"
|
||||
"(ops vec2"
|
||||
" (pub fn length ((self (* const vec2))) float (return 1.0))"
|
||||
" (fn sum-of ((self vec2)) float (return (. self x))))"
|
||||
" (fn sum-of ((self vec2)) float (return (. self x)))"
|
||||
" (fn scale ((self (* vec2))) void (= (. self x) 2.0)))"
|
||||
"(fn mk () vec2 (return #(vec2 : 1.0 2.0)))"
|
||||
"(fn f () void (var v vec2 #(vec2 : 1.0 2.0)) (var p (* vec2) (& v)) "
|
||||
(apply string-append body) ")"))
|
||||
@@ -111,6 +112,19 @@
|
||||
(reports? (ops-src "(.nope v)") "no such method on"))
|
||||
(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 "a self spread over the parameter is a pointer self too"
|
||||
(emits? (string-append
|
||||
"(record w ((x int)))"
|
||||
"(ops w (fn get ((self * const w)) int (return (. self x))))"
|
||||
"(fn f () int (var a w #(w : 1)) (var p (* const w) (& a))"
|
||||
" (return (+ (.get a) (.get p))))")
|
||||
"wːget(&a) + wːget(p)"))
|
||||
(test-assert "a const receiver is not handed to a method that may change it"
|
||||
(reports? (ops-src "(var c (* const vec2) p) (.scale c)")
|
||||
"this one is const"))
|
||||
(test-assert "one that cannot change it takes it"
|
||||
(emits? (ops-src "(var c (* const vec2) p) (var n float (.length c))")
|
||||
"vec2ːlength(c)"))
|
||||
(test-assert "an address cannot be taken of a call"
|
||||
(reports? (ops-src "(.length (mk))") "receiver is not an lvalue"))
|
||||
;; the inner call has to be typed to find the outer one's receiver
|
||||
@@ -231,6 +245,11 @@
|
||||
"(spec (p T) (fn s ((a (* const T))) void))"
|
||||
"(realize (p v) (fn s ((a v)) void (return)))")
|
||||
"arguments do not match"))
|
||||
(test-assert "but not on how a pointer is spelled"
|
||||
(emits? (string-append "(record v ((x int)))"
|
||||
"(spec (p T) (fn s ((a * const T)) void))"
|
||||
"(realize (p v) (fn s ((a (* const v))) void (return)))")
|
||||
"void vːpːs (const v * a)"))
|
||||
(test-assert "a method name already taken on the type is refused"
|
||||
(reports? (string-append "(record v ((x int)))"
|
||||
"(ops v (fn s ((a (* const v))) void (return)))"
|
||||
|
||||
Reference in New Issue
Block a user