More permissive cast-matching in `function | ...` expressions
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
**Is your feature request related to a problem? Please describe.**
```fsharp
type Foo =
inherit IDisposable
let blah () =
([] : Foo list)
|> Seq.iter (function | :? IDisposable as x -> ())
```
This fails with a rather amusing combination of two errors:
* At `function`: Incomplete pattern matches on this expression. For example, the value '``some-other-subtype``' may indicate a case not covered by the pattern(s).
* At `:? IDisposable`: This type test or downcast will always hold.
The error messages are telling me that the match is incomplete and complete at the same time!
**Describe the solution you'd like**
Accept the definition. It's presumably semantically equivalent to:
```fsharp
let blah () =
([] : Foo list)
|> Seq.iter (fun (x : IDisposable) -> ())
```
**Describe alternatives you've considered**
Just don't do this. Users can always do an explicit type annotation, and the code is even shorter! The failure mode just amused me.
This is super low priority, of course.
Contributor guide
Assessment
This issue has not been assessed yet.