refuse a field a struct declared here does not have
The path was walked on and handed to cc, which named the missing field only in C; a test leaned on a struct s an earlier test had declared.
This commit is contained in:
@@ -742,7 +742,8 @@ whitespace aside, THEN?"
|
||||
(not (emits? "(struct pt ((x int))) (fn f ((p (* (struct pt)))) int (return (. (* p) x)))"
|
||||
"*(p).x")))
|
||||
(test-assert "member access through a cast"
|
||||
(emits? (in-fn "(var n int (. (* (cast a (* (struct s)))) f))")
|
||||
(emits? (string-append "(struct s ((f int)))"
|
||||
(in-fn "(var n int (. (* (cast a (* (struct s)))) f))"))
|
||||
"(*(struct s*)a).f"))
|
||||
;; ...without gaining parens where none are due
|
||||
(test-assert "a bare dereference is left alone"
|
||||
@@ -884,6 +885,14 @@ whitespace aside, THEN?"
|
||||
(test-assert "which one step through it does not need"
|
||||
(not (warns? (in-fn "(var t (* struct tm) 0) (= (. t a) 1)")
|
||||
"cannot type")))
|
||||
(test-assert "but a struct declared here has only the fields it names"
|
||||
(reports? (in-line "(= (. p z) 1)") "no field of this name"))
|
||||
(test-assert "the last step included"
|
||||
(reports? (in-line "(= (. lp a z) 1)") "no field of this name"))
|
||||
(test-assert "an indexed one by its name"
|
||||
(reports? (string-append "(struct v ((xs [int 2])))"
|
||||
(in-fn "(var w (struct v)) (= (. w [ys 0]) 1)"))
|
||||
"no field of this name"))
|
||||
;; the arrow is `%->' and nothing else writes one, so a bare `->'
|
||||
;; is an ordinary head -- a threading macro that nobody imported,
|
||||
;; and a call like any other unknown
|
||||
|
||||
Reference in New Issue
Block a user