KEMBAR78
[Regression] Compiler is unable to compile specific flavor of type check in patterns · Issue #16447 · dotnet/fsharp · GitHub
Skip to content

[Regression] Compiler is unable to compile specific flavor of type check in patterns #16447

@En3Tho

Description

@En3Tho

Please provide a succinct description of the issue.

I've found a case where compiler is not able to compile the code it used to compile before.
This particular flavor of pattern macthing is used to help compiler figure out some overload complexities

Repro steps

Provide the steps required to reproduce the problem:

open System

module Repro =
    let fail1() =
        let x: Result<unit, exn> = Error (NullReferenceException())
        match x with
        | Error (_: exn & :? System.NullReferenceException) -> // Unexpected symbol ':?' in pattern (FS0010)
            printfn "NullRef!"
        | _ ->
            ()

    let fail2() =
        let x: Result<unit, exn> = Error (Exception())
        match x with
        | Error (_: exn & (:? System.NullReferenceException)) -> // Constraint intersection syntax may only be used with flexible types, e.g. '#IDisposable & #ISomeInterface'. (FS3572)
            printfn "NullRef"
        | _ ->
            printfn "Not a NullRef"

Repro.fail1()
Repro.fail2()

Net6/7 output: (compiles and runs)

NullRef!
Not a NullRef

Net8 fails to build the app with errors specified in the code as comments

Metadata

Metadata

Assignees

Labels

Area-Compiler-Syntaxlexfilter, indentation and parsingBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions