Simplify flat contracts for Value types
Potentially speeds up contracts checks for types like False or Boolean.
This commit is contained in:
parent
1ba8e5ba33
commit
295a4b7e39
|
@ -626,7 +626,11 @@
|
|||
[(Syntax: t)
|
||||
(syntax/sc (t->sc t))]
|
||||
[(Value: v)
|
||||
(flat/sc #`(flat-named-contract '#,v (lambda (x) (equal? x '#,v))) v)]
|
||||
(if (and (c:flat-contract? v)
|
||||
;; regexps don't match themselves when used as contracts
|
||||
(not (regexp? v)))
|
||||
(flat/sc #`(quote #,v))
|
||||
(flat/sc #`(flat-named-contract '#,v (lambda (x) (equal? x '#,v))) v))]
|
||||
[(Param: in out)
|
||||
(parameter/sc (t->sc in) (t->sc out))]
|
||||
[(Hashtable: k v)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
(check-equal? v #f)
|
||||
(check-equal? ((cast f (Boolean -> Boolean)) #t) #t)
|
||||
(check-equal? v #t)
|
||||
(check-exn #rx"expected: \\(or/c #f #t\\)\n *given: \"hello\""
|
||||
(check-exn #rx"expected: boolean\\?\n *given: \"hello\""
|
||||
(λ () ((cast f (String -> String)) "hello")))
|
||||
(check-equal? v #t
|
||||
"if the previous test hadn't errored, this would be \"hello\" with type Boolean"))
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
(check-equal? v #f)
|
||||
(check-equal? ((cast f (Boolean -> Boolean)) #t) #t)
|
||||
(check-equal? v #t)
|
||||
(check-exn #rx"expected: \\(or/c #f #t\\)\n *given: \"hello\""
|
||||
(check-exn #rx"expected: boolean\\?\n *given: \"hello\""
|
||||
(λ () ((cast f (String -> String)) "hello")))
|
||||
(check-equal? v #t
|
||||
"if the previous test hadn't errored, this would be \"hello\" with type Boolean"))
|
||||
|
|
|
@ -237,7 +237,7 @@
|
|||
(lambda (f) (f 6))
|
||||
(lambda (x) 'bad)
|
||||
#:untyped
|
||||
#:msg #rx"promised: \\(or/c #f #t\\).*produced: 'bad.*blaming: untyped")
|
||||
#:msg #rx"promised: boolean\\?.*produced: 'bad.*blaming: untyped")
|
||||
;; Struct predicates should not have a contract
|
||||
(t-int ctc
|
||||
(lambda (foo?)
|
||||
|
|
Loading…
Reference in New Issue
Block a user