Skip to content

Commit cd181f9

Browse files
author
Andrew Kent
authored
check-below use props if with-refinements on
1 parent f372bdd commit cd181f9

File tree

2 files changed

+65
-20
lines changed

2 files changed

+65
-20
lines changed

typed-racket-lib/typed-racket/typecheck/check-below.rkt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,29 @@
107107

108108

109109
[((tc-result1: t1 p1 o1) (tc-result1: t2 p2 o2))
110+
(define (perform-check!)
111+
(cond
112+
[(not (subtype t1 t2 o1))
113+
(expected-but-got t2 t1)]
114+
[(and (not (prop-set-better? p1 p2))
115+
(object-better? o1 o2))
116+
(type-mismatch p2 p1 "mismatch in proposition")]
117+
[(and (prop-set-better? p1 p2)
118+
(not (object-better? o1 o2)))
119+
(type-mismatch (print-object o2) (print-object o1) "mismatch in object")]
120+
[(and (not (prop-set-better? p1 p2))
121+
(not (object-better? o1 o2)))
122+
(type-mismatch (format "`~a' and `~a'" p2 (print-object o2))
123+
(format "`~a' and `~a'" p1 (print-object o1))
124+
"mismatch in proposition and object")])
125+
(ret t2 (fix-props p2 p1) (fix-object o2 o1)))
110126
(cond
111-
[(not (subtype t1 t2 o1))
112-
(expected-but-got t2 t1)]
113-
[(and (not (prop-set-better? p1 p2))
114-
(object-better? o1 o2))
115-
(type-mismatch p2 p1 "mismatch in proposition")]
116-
[(and (prop-set-better? p1 p2)
117-
(not (object-better? o1 o2)))
118-
(type-mismatch (print-object o2) (print-object o1) "mismatch in object")]
119-
[(and (not (prop-set-better? p1 p2))
120-
(not (object-better? o1 o2)))
121-
(type-mismatch (format "`~a' and `~a'" p2 (print-object o2))
122-
(format "`~a' and `~a'" p1 (print-object o1))
123-
"mismatch in proposition and object")])
124-
(ret t2 (fix-props p2 p1) (fix-object o2 o1))]
127+
[(with-refinements?)
128+
(with-naively-extended-lexical-env
129+
[#:props (list (-is-type o1 t1)
130+
(-or (PropSet-thn p1) (PropSet-els p1)))]
131+
(perform-check!))]
132+
[else (perform-check!)])]
125133

126134
;; case where expected is like (Values a ... a) but got something else
127135
[((tc-results: _ #f) (tc-results: _ (? RestDots?)))
@@ -134,12 +142,6 @@
134142
(fix-results expected)]
135143

136144
;; case where both have no '...', or both have '...'
137-
;; NOTE: we ignore the propsets and objects... not sure
138-
;; why---maybe there's an assumption that users
139-
;; can't specify props/objects for multiple values?
140-
;; seems like we should add some checks to this doesn't
141-
;; turn into an error in the future that we can't fix w/o
142-
;; breaking programs that relied on it being broken.
143145
[((tc-results: tcrs1 db1)
144146
(tc-results: tcrs2 db2))
145147
(cond
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
;; see Typed Racket GH issue #640
2+
#lang typed/racket #:with-refinements
3+
4+
(: lyst : (-> ([arg : Integer])
5+
(Refine [result : (List Integer)]
6+
(= (car result) arg))))
7+
(define (lyst arg)
8+
(define result (list arg))
9+
(assert (= (car result) arg))
10+
result)
11+
12+
(: lyst-car : (-> ([lyst : (List Integer)])
13+
(Refine [result : Integer]
14+
(= result (car lyst)))))
15+
(define (lyst-car lst)
16+
(car lst))
17+
18+
(: lyst+ : (-> ([a : (List Integer)]
19+
[b : (List Integer)])
20+
(Refine [result : (List Integer)]
21+
(= (car result) (+ (car a) (car b))))))
22+
(define (lyst+ a b)
23+
(lyst (+ (lyst-car a) (lyst-car b))))
24+
25+
(: lyst1+ : (-> ([a : (List Integer)]
26+
[b : (List Integer)])
27+
(Refine [result : (List Integer)]
28+
(= (car result) (+ (car a) (car b))))))
29+
(define (lyst1+ a b)
30+
(define res (lyst (+ (lyst-car a) (lyst-car b))))
31+
res)
32+
33+
34+
(: lyst2+ : (-> ([a : (List Integer)]
35+
[b : (List Integer)])
36+
(values (Refine [result : (List Integer)]
37+
(= (car result) (+ (car a) (car b))))
38+
(Refine [result : (List Integer)]
39+
(= (car result) (+ (car a) (car b)))))))
40+
(define (lyst2+ a b)
41+
(values (lyst (+ (lyst-car a) (lyst-car b)))
42+
(lyst (+ (lyst-car a) (lyst-car b)))))
43+

0 commit comments

Comments
 (0)