rackunit icon indicating copy to clipboard operation
rackunit copied to clipboard

check-exn should not fail on opaque value

Open sorawee opened this issue 8 months ago • 1 comments

> (require typed/rackunit)
> (struct opaque ())
> (check-exn (lambda (e) (println e) #t) (lambda () (opaque)))
(exn:fail:contract:blame "check-exn-imp: contract violation\n  any-wrap/c: Unable to protect opaque value passed as `Any`\n  value: #<opaque>\n  in: the range of\n      the 2nd argument of\n      the range of\n      (->\n       #:expression\n       Any\n       #:location\n       Any\n       (->*\n        ((or/c\n          pregexp?\n          (and/c regexp? (not/c pregexp?))\n          (or/c\n           struct-predicate-procedure?\n           struct-type-property-predicate-procedure?\n           (-> any/c any)))\n         (-> Any))\n        (any/c)\n        void?))\n  contract from: (interface for check-exn-imp)\n  blaming: <pkgs>/rackunit-typed/rackunit/main.rkt\n   (assuming the contract is correct)\n  at: <pkgs>/rackunit-typed/rackunit/main.rkt" #<continuation-mark-set> #<blame-no-swap>)

This should not occur. Since check-exn doesn't care about the result, one possible fix is to wrap the thunk so that it always return a non-opaque value. E.g.:

> (check-exn (lambda (e) (println e) #t) (lambda () (opaque) #t))
--------------------
FAILURE [,bt for context]
name:       check-exn
location:   string:1:0
params:     '(#<procedure> #<procedure>)
message:    "No exception raised"
--------------------

works as expected.

sorawee avatar Mar 19 '25 16:03 sorawee

We should just change typed/rackunit to use unsafe-require/typed in a bunch of places.

samth avatar Mar 20 '25 19:03 samth