Use correct contract for Procedure type
The only problem with this contract is that it does not produce a very good error message original commit: 27d3042ad6008432428368bda882987f1f8a23c1
This commit is contained in:
parent
30da00ba79
commit
04bc05d607
23
collects/tests/typed-racket/fail/procedure-top.rkt
Normal file
23
collects/tests/typed-racket/fail/procedure-top.rkt
Normal file
|
@ -0,0 +1,23 @@
|
|||
#;
|
||||
(exn-pred exn:fail:contract:arity?)
|
||||
#lang racket/load
|
||||
|
||||
;; fail version
|
||||
|
||||
(module example typed/racket
|
||||
;; coerces into unapplicable function
|
||||
(: id (Procedure -> Procedure))
|
||||
(define (id x) x)
|
||||
|
||||
(: f (Integer -> Integer))
|
||||
(define (f x) (+ x 1))
|
||||
|
||||
(define g (id f))
|
||||
|
||||
;; contract here should make sure g is not applicable
|
||||
(provide g))
|
||||
|
||||
(require 'example)
|
||||
|
||||
;; g should now be unapplicable via case-> contract
|
||||
(g 3)
|
21
collects/tests/typed-racket/succeed/procedure-top.rkt
Normal file
21
collects/tests/typed-racket/succeed/procedure-top.rkt
Normal file
|
@ -0,0 +1,21 @@
|
|||
#lang racket
|
||||
|
||||
;; succeed version
|
||||
|
||||
(module example typed/racket
|
||||
;; coerces into unapplicable function
|
||||
(: id (Procedure -> Procedure))
|
||||
(define (id x) x)
|
||||
|
||||
(: f (Integer -> Integer))
|
||||
(define (f x) (+ x 1))
|
||||
|
||||
(define g (id f))
|
||||
|
||||
;; contract here should allow application
|
||||
(provide id))
|
||||
|
||||
(require 'example)
|
||||
|
||||
;; id's argument is procedure?, result is (case->)
|
||||
(id +)
|
|
@ -129,7 +129,7 @@
|
|||
(loop t (not pos?) (not from-typed?) structs-seen kind))
|
||||
(define (t->c/fun f #:method [method? #f])
|
||||
(match f
|
||||
[(Function: (list (top-arr:))) #'procedure?]
|
||||
[(Function: (list (top-arr:))) (if pos? #'(case->) #'procedure?)]
|
||||
[(Function: arrs)
|
||||
(set-chaperone!)
|
||||
;; Try to generate a single `->*' contract if possible.
|
||||
|
|
Loading…
Reference in New Issue
Block a user