racket / option-contract

Other
3 stars 10 forks source link

`option/c` works inconsistently in DrRacket #3

Open dented42 opened 9 months ago

dented42 commented 9 months ago

running this file:

#lang racket
(module thing racket
  (require racket/contract/option)
  (provide (contract-out [nothing proc/c] [something proc/c] [something* proc/c]))
  (define (my-list args) (list args))
  (define proc/c (option/c (-> any/c any/c) #:with-contract #t))
  (define something (λ (x) (my-list x)))
  (define something* (λ (x) (list x)))
  (define nothing (λ (x) '())))
(require rackunit 'thing)
(map value-contract `(,nothing ,something ,something*))
(check-equal? (value-contract something) (value-contract nothing))
(check-equal? (value-contract something) (value-contract something*))

in the command line produces the following (expected) output:

'(#<option> #<option> #<option>)

However running it in DrRacket (with dynamic properties set to 'Debugging', the default) produces the following:

image

I genuinely don't know whether to file this issue with racket, DrRacket, or option contracts. I'm happy to refile it elsewhere if needed.

dented42 commented 9 months ago

Another weirdness is that if #:with-contract is #f then (check-equal? (value-contract something) (value-contract (tweak-option (tweak-option something)))) fails. REPL experimentation makes it seems like tweak-option is behaving normally for nothing but acting like exercise-option for something.

rfindler commented 9 months ago

It looks like errortrace might be relevant. Running racket -l errortrace -t <filename.rkt> produces the same answer as in DrRacket.

usaoc commented 9 months ago

After some trial and error, compile-enforce-module-constants appears to be the root of the problem. If you use eval with compile-enforce-module-constants set to #f, then it fails. Specifically, something references the my-list variable defined in the same module, so that makes it even more likely.

Edit: One more thing I found is that “non-trivial procedures” all work like something, say, if you try (λ (x) (println x)). I have no idea what’s exactly the problem.