typed-racket
typed-racket copied to clipboard
Bad optimization with (if (pair? rest) …) on polymorphic rest argument (unsound)
What version of Racket are you using?
6.6.0.1
What program did you run?
#lang typed/racket
((λ #:∀ (A ...) [rest : A ... A]
(if (pair? rest)
#t
#f))
1)
; => #f
What should have happened?
The result should be #t, but the program outputs #f. When typing this expression at the REPL, we can see racket incorrectly inferred the return type is False.
Without the (if … #t #f), the program outputs #t as expected:
#lang typed/racket
((λ #:∀ (A ...) [rest : A ... A]
(pair? rest))
1)
; => #t
Also, when using a regular Any * rest argument instead of the polymorphic A ... A, the result is correct:
#lang typed/racket
((λ [rest : Any *]
(if (pair? rest)
#t
#f))
1)
; => #t
I couldn't find a way to turn this into unsafe behaviour, so the problem is "just" incorrect results.