Unexpected FS0812 when property has same name as DU case
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.
This is not related to shorthand lambda, it also fails for normal lambdas:
let onlyIdA (ids: MyId list) = ids |> List.choose (fun x -> x.IdA)
^^^^^
We should probably add a warning when defining a member with the same name as a DU case.
We might also want to fix the current error message.
It for sure has been like that for some time, definitely not a bug.
This is likely to be an error recovery issue FS0812 is reported using error(Error(.....)) so it will hide the previous raised error.
I think FS0812 should use errorR(Error(....)) to allow error cascading as expected