Skip to content

Commit 8171fb9

Browse files
authored
Merge pull request #993 from herbie-fp/fix-casts
Fix programs with casts and `!` annotations
2 parents 3aeb648 + 2cabb9a commit 8171fb9

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/syntax/syntax-check.rkt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
[#`(! #,props ... #,body)
5353
(check-properties* props '() error! deprecated-ops)
5454
(loop body vars)]
55+
[#`(cast #,arg) (loop arg vars)]
56+
[#`(cast #,args ...)
57+
(error! stx "Invalid `cast` expression with ~a arguments (expects 1)" (length args))
58+
(unless (null? args)
59+
(loop (first args) vars))]
5560
[#`(,(? (curry set-member? '(+ * and or))) #,args ...)
5661
;; Variary (minimum 0 arguments)
5762
(for ([arg args])
@@ -152,14 +157,20 @@
152157
(define (check-program* stx vars props body error!)
153158
(unless (list? vars)
154159
(error! stx "Invalid arguments list ~a; must be a list" stx))
155-
(define vars* (filter identifier? vars))
156-
(when (list? vars)
157-
(for ([var vars]
158-
#:unless (identifier? var))
159-
(error! stx "Argument ~a is not a variable name" var))
160-
(when (check-duplicate-identifier vars*)
161-
(error! stx "Duplicate argument name ~a" (check-duplicate-identifier vars*))))
162160
(define deprecated-ops (mutable-set))
161+
(define vars*
162+
(reap [sow]
163+
(when (list? vars)
164+
(for ([var (in-list vars)])
165+
(match var
166+
[(? identifier? x) (sow var)]
167+
[#`(! #,props ... #,name)
168+
(check-properties* props (immutable-bound-id-set '()) error! deprecated-ops)
169+
(cond
170+
[(identifier? name) (sow name)]
171+
[else (error! var "Annotated argument ~a is not a variable name" name)])])))))
172+
(when (check-duplicate-identifier vars*)
173+
(error! stx "Duplicate argument name ~a" (check-duplicate-identifier vars*)))
163174
(check-properties* props (immutable-bound-id-set vars*) error! deprecated-ops)
164175
(check-expression* body (immutable-bound-id-set vars*) error! deprecated-ops)
165176
(for ([op (in-set deprecated-ops)])

src/syntax/type-check.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
(unless (equal? ift-repr iff-repr)
9696
(error! stx "If statement has different types for if (~a) and else (~a)" ift-repr iff-repr))
9797
ift-repr]
98-
[#`(! #,props ... #,body) (loop body (apply dict-set prop-dict props) ctx)]
98+
[#`(! #,props ... #,body) (loop body (apply dict-set prop-dict (map syntax->datum props)) ctx)]
9999
[#`(,(? (curry hash-has-key? (*functions*)) fname) #,args ...)
100100
; TODO: inline functions expect uniform types, this is clearly wrong
101101
(match-define (list vars prec _) (hash-ref (*functions*) fname))

0 commit comments

Comments
 (0)