Bogdanp / racket-review

A linter for Racket.
BSD 3-Clause "New" or "Revised" License
41 stars 4 forks source link

False positive shadowing when reviewing Typed Racket code? #10

Open jessealama opened 3 years ago

jessealama commented 3 years ago

Take a look at this Typed Racket code:

#lang typed/racket/base

(provide do-it)

(: do-it (-> (Listof Number)
             (List (Listof Integer)
                   (Listof Integer))))
(define (do-it nums)
  (define evens (filter (lambda ([n : Any]) (and (integer? n) (exact? n) (even? n)))
                        nums))
  (define odds (filter (lambda ([n : Any]) (and (integer? n) (exact? n) (odd? n)))
                       nums))
  (list evens odds))

Putting aside that this code doesn't quite pass the type checker, what's puzzling is that when this code is passed through review, it generates a warning:

mini.rkt:11:34:warning:identifier 'n' shadows an earlier binding

This seems wrong to me. Sure, there are two lambdas there with the same formal parameter, but the second one surely doesn't shadow the first. It's not even in the same scope.

When you turn this into a plain Racket module, review doesn't complain.

It seems to me that TR is either rewriting the code before review sees it, or perhaps there's an issue somewhere in review? Do you have some advice for getting rid of this warning?

Bogdanp commented 3 years ago

Typed Racket isn't really supported by review because review doesn't expand the code it lints, so I'd have to bake in a bunch of typed-racket-specific rules into it and I don't know if I'd want to do that because I don't use TR atm.

jessealama commented 3 years ago

Thanks for thinking about this. I realize TR is a bit off the radar for review. I'm also willing to take a look at the issue and see if I can fix it.