Remove distinction between check and non check variant of check-subforms-unit.

Use new merge-tc-results as well.
This revealed some buggy tests as well which are also fixed.
This commit is contained in:
Eric Dobson 2014-05-27 09:14:28 -07:00
parent 447b52855f
commit 17c43c35ec
7 changed files with 20 additions and 49 deletions

View File

@ -21,19 +21,6 @@
;; get called with the wrong kind of arguments by the exception ;; get called with the wrong kind of arguments by the exception
;; mechanism. The right thing is to use the exception predicate. ;; mechanism. The right thing is to use the exception predicate.
(define (transpose l) (apply map list l))
;; combine-types : Values * -> tc-results
(define (combine-types . args)
(match args
[(list (tc-results: tss) ...)
(unless (apply = (map length tss))
(tc-error "Exception handlers and body did not all have the same number of results: ~a" (map length tss)))
;; transpose and union
(let ([ts* (transpose tss)])
(ret (map (lambda (ts) (apply Un ts)) ts*)))]
[_ (int-err "Internal error: unsupported exception result type in: ~a" args)]))
;; Does a depth first search of the syntax object. For each sub object it attempts to match it ;; Does a depth first search of the syntax object. For each sub object it attempts to match it
;; against the provide syntax-parse patterns. ;; against the provide syntax-parse patterns.
(define-syntax find-syntax (define-syntax find-syntax
@ -52,15 +39,14 @@
[_ (void)])))])) [_ (void)])))]))
;; find the subexpressions that need to be typechecked in an ignored form ;; find the subexpressions that need to be typechecked in an ignored form
;; syntax -> any ;; syntax (or/c #f tc-results/c) -> full-tc-results/c
(define (check-subforms/with-handlers form [expected #f]) (define (check-subforms/with-handlers form expected)
(define handler-tys '()) (define handler-results '())
(define body-ty #f) (define body-results #f)
(define body-stx #f)
;; tc-result1 -> tc-results ;; tc-result1 -> tc-results
;; The result of applying the function to a single argument of the type of its first argument ;; The result of applying the function to a single argument of the type of its first argument
;; FIXME: This is the wrong type, see above fixme ;; FIXME: This is the wrong type, see above fixme
(define (get-result-ty t) (define (get-range-result t)
(let loop ((t t)) (let loop ((t t))
(match t (match t
[(Function: (list _ ... (arr: (list arg1) _ _ #f (list (Keyword: _ _ #f) ...)) _ ...)) [(Function: (list _ ... (arr: (list arg1) _ _ #f (list (Keyword: _ _ #f) ...)) _ ...))
@ -81,28 +67,11 @@
[stx:exn-handler^ [stx:exn-handler^
(match (single-value #'stx) (match (single-value #'stx)
[(tc-result1: t) [(tc-result1: t)
(set! handler-tys (cons (get-result-ty t) handler-tys))])] (set! handler-results (cons (get-range-result t) handler-results))])]
;; this is the body of the with-handlers
[stx:exn-body^
(set! body-stx #'stx)
(set! body-ty (tc-expr #'stx))])
(apply combine-types body-ty handler-tys))
;; syntax tc-results -> tc-results
(define (check-subforms/with-handlers/check form expected)
(define body-results #f)
(find-syntax form
;; if this needs to be checked
[stx:with-type^
;; the form should be already ascribed the relevant type
(tc-expr #'stx)]
;; this is a handler function
[stx:exn-handler^
(tc-expr/check #'stx (ret (-> (Un) (tc-results->values expected))))]
;; this is the body of the with-handlers ;; this is the body of the with-handlers
[stx:exn-body^ [stx:exn-body^
(set! body-results (tc-expr/check #'stx expected))]) (set! body-results (tc-expr/check #'stx expected))])
body-results) (merge-tc-results (cons body-results handler-results)))
;; typecheck the expansion of a with-handlers form ;; typecheck the expansion of a with-handlers form
;; syntax -> void ;; syntax -> void

View File

@ -15,8 +15,7 @@
(define-signature check-subforms^ (define-signature check-subforms^
([cond-contracted check-subforms/ignore (syntax? . -> . void?)] ([cond-contracted check-subforms/ignore (syntax? . -> . void?)]
[cond-contracted check-subforms/with-handlers (syntax? . -> . full-tc-results/c)] [cond-contracted check-subforms/with-handlers (syntax? (or/c tc-results/c #f) . -> . full-tc-results/c)]))
[cond-contracted check-subforms/with-handlers/check (syntax? tc-results/c . -> . full-tc-results/c)]))
(define-signature check-class^ (define-signature check-class^
([cond-contracted check-class (syntax? (or/c tc-results/c #f) . -> . full-tc-results/c)])) ([cond-contracted check-class (syntax? (or/c tc-results/c #f) . -> . full-tc-results/c)]))

View File

@ -91,9 +91,7 @@
(check-class form expected)] (check-class form expected)]
[stx:exn-handlers^ [stx:exn-handlers^
(register-ignored! form) (register-ignored! form)
(if expected (check-subforms/with-handlers form expected) ]
(check-subforms/with-handlers/check form expected)
(check-subforms/with-handlers form))]
;; explicit failure ;; explicit failure
[t:typecheck-failure [t:typecheck-failure
(explicit-fail #'t.stx #'t.message #'t.var)] (explicit-fail #'t.stx #'t.message #'t.var)]

View File

@ -16,7 +16,7 @@ END
;; should error ;; should error
(with-handlers ([exn:fail:contract? (with-handlers ([exn:fail:contract?
(lambda (e) (lambda: ([e : exn])
(when (regexp-match "index is out of range for empty vector" (when (regexp-match "index is out of range for empty vector"
(exn-message e)) (exn-message e))
(display "passed\n")))]) (display "passed\n")))])

View File

@ -7,13 +7,11 @@
(: g (All (x) (x -> x))) (: g (All (x) (x -> x)))
(define (g x) x) (define (g x) x)
(: v (Listof (U inf Byte))) (: v (Listof (U inf Number)))
(define v (define v
(list (list
(with-handlers ((void values)) 2)
(with-handlers ((void add1)) 3) (with-handlers ((void add1)) 3)
(with-handlers ((void f)) 4) (with-handlers ((void f)) 4)))
(with-handlers ((void g)) 5)))
(list (list

View File

@ -118,7 +118,8 @@
;; exception handling ;; exception handling
[tc-e (with-handlers ([void (λ (x) (values 0 0))]) (values "" "")) [tc-e (with-handlers ([void (λ (x) (values 0 0))]) (values "" ""))
#:ret (ret (list (t:Un -Zero -String) (t:Un -Zero -String)))] #:ret (ret (list (t:Un -Zero -String) (t:Un -Zero -String))
(list -true-filter -true-filter))]
(tc-e (make-temporary-file) -Path) (tc-e (make-temporary-file) -Path)
(tc-e (make-temporary-file "ee~a") -Path) (tc-e (make-temporary-file "ee~a") -Path)

View File

@ -2947,6 +2947,12 @@
#:ret (ret -Nat -true-filter) #:ret (ret -Nat -true-filter)
#:expected (ret -Nat -no-filter)] #:expected (ret -Nat -no-filter)]
[tc-e
(with-handlers ([exn:fail? (λ (exn) #f)])
5)
#:ret (ret Univ -top-filter)
#:expected (ret Univ -no-filter)]
[tc-e [tc-e
(lambda (a . b) (apply values a b)) (lambda (a . b) (apply values a b))