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

Misleading error message when using [<CustomEquality>] or [<CustomComparison>] with a non-structural type #960

Open
kbattocchi opened this issue Feb 11, 2016 · 4 comments

Comments

@kbattocchi
Copy link
Contributor

If you mistakenly add the [<CustomEquality>] or [CustomComparison>] (or both) attributes to a non-structural type then you get a very misleading error message:

[<CustomEquality>]
type T() =
    override __.Equals(_) = true

error FS0377: This type uses an invalid mix of the attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' attributes

This causes confusion (see e.g. this StackOverflow question).

@KevinRansom KevinRansom added the Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. label Jan 6, 2017
@dsyme dsyme added Feature Specification and removed Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. labels May 9, 2017
@cartermp cartermp added this to the Unknown milestone Aug 25, 2018
@nojaf
Copy link
Contributor

nojaf commented Jun 15, 2023

@vzarytovskii what could be done to improve this error message?

@snuup
Copy link

snuup commented Dec 29, 2023

@nojaf Suggestions: 1. Explain valid combinations. 2. Add documentation about this error message, as far as I see there is none yet.

@nojaf
Copy link
Contributor

nojaf commented Dec 29, 2023

@nojaf Explain what combination is valid!

Jeesh, pick another writing style to address me there pal.

@smoothdeveloper
Copy link
Contributor

AFAIU, those attributes shouldn't be a valid thing when tucked on ad-hoc structs/classes, so it is good it is an error already.

For this particular case, the error message could be:

The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes or structures, nor enums, but only on discriminated unions or record types.

Only drawback of this message is, if we come up with more of such types where the attributes are invalid/valid, then the message will need tweak.

The current error message bothers me a bit with "attributes" being repeated.

In meantime, "Jeesh" isn't offended of being addressed in any style 🙂 and users are sometimes exclamatory when addressing the compiler as an entity or simply greeting others!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

8 participants