Skip to content

Cond Branch with (procedure? ret-val) Runs When ret-val is 0 #1045

@Noble-Mushtak

Description

@Noble-Mushtak

What version of Racket are you using?

I am using Racket v8.0 [cs].

What program did you run?

#lang typed/racket
(define buffer (make-bytes 0))
(define ret-val (read-bytes-avail! buffer))
(cond [(eof-object? ret-val) 0]
      [(exact-positive-integer? ret-val) 0]
      [(procedure? ret-val) (ret-val 1 1 2 3)])

What should have happened?

Nothing should have happened: ret-val is 0, so none of the cond branches should apply. However, for some reason, the third cond branch runs, leading to the error message below.

If you got an error message, please include it here.

application: not a procedure;
 expected a procedure that can be applied to arguments
  given: 0
  context...:
   /home/noble/test.rkt:7:0
   body of "/home/noble/test.rkt"

I think this is related to this issue I filed in the Racket repo earlier. Basically, the signature of read-bytes-avail!, according to Typed Racket is:

> read-bytes-avail!
- : (->* (Bytes)
         (Input-Port Nonnegative-Integer Nonnegative-Integer)
         (U (-> (U Exact-Positive-Integer False)
                (U Exact-Nonnegative-Integer False)
                (U Exact-Positive-Integer False)
                (U Exact-Nonnegative-Integer False)
                Any)
            EOF
            Exact-Positive-Integer))

However, this signature does not allow for the possibility for returning 0, even though it is possible for read-bytes-avail! to return 0, as shown in the above program.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions