typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

Bad optimization with (if (pair? rest) …) on polymorphic rest argument (unsound)

Open SuzanneSoy opened this issue 9 years ago • 3 comments

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.

SuzanneSoy avatar Aug 02 '16 14:08 SuzanneSoy