Skip to content

Commit

Permalink
Only generate poly contracts for functions
Browse files Browse the repository at this point in the history
Closes PR 13815
  • Loading branch information
takikawa committed Jun 18, 2013
1 parent 61b509d commit bafaf52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions collects/tests/typed-racket/fail/pr13815.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#;
(exn:pred #rx"Type (All (a) Flonum) could not be converted to a contract")
#lang typed/racket
(require/typed racket/base [list (All (a) Float)])
(* 3.3 list)

8 changes: 7 additions & 1 deletion collects/tests/typed-racket/unit-tests/contract-tests.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
(t (-Number . -> . -Number))
(t (-Promise -Number))
(t (-set Univ))
))
;; Adapted from PR 13815
(t (-poly (a) (-> a a)))
(t (-poly (a) (-mu X (-> a X))))
(t (-poly (a) (-poly (b) (-> a a))))
(t (-poly (a) (-App (-poly (b) (-> a a)) (list -Number) #'#f)))
(t/fail (-poly (a) -Flonum))
(t/fail (-poly (a) (-set -Number)))))

(define-go contract-tests)
(provide contract-tests)
11 changes: 11 additions & 0 deletions collects/typed-racket/private/type-contract.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@
[(F: v) (cond [(assoc v (vars)) => second]
[else (int-err "unknown var: ~a" v)])]
[(Poly: vs b)
;; Don't generate poly contracts for non-functions
(define function-type?
(let loop ([ty ty])
(match (resolve ty)
[(Function: _) #t]
[(Union: elems) (andmap loop elems)]
[(Poly: _ body) (loop body)]
[(PolyDots: _ body) (loop body)]
[_ #f])))
(unless function-type?
(exit (fail)))
(if (not (from-untyped? typed-side))
;; in typed positions, no checking needed for the variables
(parameterize ([vars (append (for/list ([v (in-list vs)]) (list v #'any/c)) (vars))])
Expand Down

0 comments on commit bafaf52

Please sign in to comment.