refine if: create sym val only when test is sym bool

This commit is contained in:
Stephen Chang 2016-10-31 12:28:18 -04:00
parent 593f4f5881
commit 4f400b5e0a
2 changed files with 6 additions and 1 deletions

View File

@ -491,10 +491,14 @@
;; ---------------------------------
;; if
;; TODO: this is not precise enough
;; specifically, a symbolic non-bool should produce a concrete val
(define-typed-syntax if
[(_ e_tst e1 e2)
[ [e_tst e_tst- : ty_tst]]
#:when (concrete? #'ty_tst)
#:when (or (concrete? #'ty_tst) ; either concrete
; or non-bool symbolic
(not (typecheck? #'ty_tst ((current-type-eval) #'Bool))))
[ [e1 e1- : ty1]]
[ [e2 e2- : ty2]]
#:when (and (concrete? #'ty1) (concrete? #'ty2))

View File

@ -107,6 +107,7 @@
#:with-msg "Constant requires a symbolic type")
(check-type b0 : Bool -> b0)
(check-type b0 : (Constant Bool) -> b0)
(check-not-type b0 : CBool)
(check-type i0 : Int -> i0)
(check-type i0 : (Constant Int) -> i0)
(check-type (if b0 1 2) : Int)