[racket] Unreachable line reached

From: Danny Yoo (dyoo at hashcollision.org)
Date: Mon Sep 17 13:30:22 EDT 2012

> I have a trivial question but I desperately need a spare pair or eyes (or
> another brain).

The 'when's here look really suspicious.  You want control flow to go
exclusively to one or the other path, but when you have 'when' like
this:


    ... (when <test> <body>) <rest>

unless an exception occurs in the <test> or <body>, control flow will
inevitably go through <rest> as well.  And I suspect you _don't_ want
that in your use in the snippet.


Try:


(let loop ([line (read-line in)])
  (when (not (eof-object? line))
    (let ([split-str (string-split line ",")])
      (cond
        [(not (= (length split-str) 3))
         (printf "[1] read-cache fails, unexpected line in cache file:
~a, ignoring.~n" line)
         (loop (read-line in))]
        [else
         (let ([path (first split-str)]
               [modtime (string->number (string-trim (second split-str)))]
               [md5 (string->bytes/utf-8 (string-trim (third split-str)))])
           (cond [(or (not path) (not modtime) (not md5))
                  (printf "[2] read-cache fails, unexpected line in
cache file: ~a, ignoring.~n" line)
                  (loop (read-line in))]

                 [(not modtime)
                  (error "fail")] ;; unreachable?

                 [else
                  (hash-set! (*cache*) path (cons modtime md5))
                  (loop (read-line in))]))]))))

Posted on the users mailing list.