dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.89k stars 783 forks source link

"This rule is never matched" warning is not shown if an active pattern is used in match expression #7177

Open vasily-kirichenko opened 5 years ago

vasily-kirichenko commented 5 years ago
let _ =
    match obj() with
    | x -> ()
    | _ -> ()
    | _ -> ()

results with proper warnings:

image

However, if an active pattern is used in match expression, there are no warnings at all:

let (|AP|_|) x = Some()

let _ =
    match obj() with
    | AP -> ()
    | _ -> ()
    | _ -> ()

image

auduchinok commented 5 years ago

Seems to be a duplicate of https://github.com/dotnet/fsharp/issues/1281#issuecomment-229061892. It looks like a thing worth fixing some day, though.

dsyme commented 5 years ago

For the above example I agree it would be good to fix.

That said, it will be a game of whack-a-mole - partial active patterns do impact on exhaustivity checking and always will, there will always be cases where the programmer feels that warnings should be given but the compiler doesn't give them.

kerams commented 1 year ago

warnOnUnused is specifically disabled when there is a "problematic" clause in order to avoid out-of-control code expansion. Is it the plan to use some heuristic to decide whether the pattern match as a whole is simple enough to go down the warn/meticulous route anyway? Maybe a pattern match complexity score, computed by some sort of a weighted multiplication of the number of clauses, when guards, disjunctions, subpatterns, etc.?