Skip to content

Unexpected FS0812 when property has same name as DU case #16646

Closed
@cmeeren

Description

@cmeeren

Consider this code:

type MyId =
    | IdA of int
    | IdB of string

    member this.IdA =
        match this with
        | IdA x -> Some x
        | _ -> None


let onlyIdA (ids: MyId list) = ids |> List.choose _.IdA

The last line fails to compile with an error on _.IdA:

Error FS0812 : The syntax 'expr.id' may only be used with record labels, properties and fields

I would expect this to compile, since IdA is indeed a property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsFeature ImprovementTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions