cryptosense / ocamllint

Detect common errors in OCaml code
BSD 2-Clause "Simplified" License
68 stars 3 forks source link

Spurious warning about identical branches of a pattern matching #26

Open vprevosto opened 6 years ago

vprevosto commented 6 years ago

In the following example (reduced from a more complex pattern matching)

let f l = match l with  _::l -> l | _ -> l

ocamllint warns about the two branches of the pattern matching being identical, while the two l identifiers do not refer to the same thing at all and should not really be considered equal.

emillon commented 6 years ago

Thanks for the report.

To make sure that it corresponds to the same value, we'd have to check which new variables are bound by the branches. A possible way to do that is whenever we try to compare two expressions for equality, first rename binders in them so that they become unique. I'm sure it's more complicated that it sounds though :/