Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cmeeren opened this issue Feb 2, 2024 · 4 comments · Fixed by #17088
Closed

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

cmeeren opened this issue Feb 2, 2024 · 4 comments · Fixed by #17088
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Feb 2, 2024

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.

@github-actions github-actions bot added this to the Backlog milestone Feb 2, 2024
@cmeeren
Copy link
Contributor Author

cmeeren commented Feb 2, 2024

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)
                                                            ^^^^^

@0101 0101 added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Diagnostics mistakes and possible improvements to diagnostics and removed Needs-Triage labels Feb 12, 2024
@0101
Copy link
Contributor

0101 commented Feb 12, 2024

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.

@vzarytovskii
Copy link
Member

It for sure has been like that for some time, definitely not a bug.

@vzarytovskii vzarytovskii added Feature Improvement Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. and removed Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. labels Feb 20, 2024
@edgarfgp
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Projects
Archived in project
4 participants