Skip to content

More permissive cast-matching in function | ... expressions #17882

@Smaug123

Description

@Smaug123

Is your feature request related to a problem? Please describe.

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions