public
Created

Producing explicit type errors for uncovered cases in Typed Racket

  • Download Gist
explicit-failure.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#lang typed/racket
 
(define-syntax (cond* stx)
(syntax-case stx ()
[(_ x clause ...)
#`(cond clause ... [else (typecheck-fail #,stx "incomplete coverage" #:covered-id x)])]))
 
(: f : (U String Integer) -> Boolean)
(define (f x)
(cond* x
[(string? x) #t]
[(exact-nonnegative-integer? x) #f]))
 
;; Produces the error:
;; Type Checker: incomplete coverage; missing coverage of Negative-Integer in:
;; (cond* x ((string? x) #t) ((exact-nonnegative-integer? x) #f))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.