fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
772 stars 194 forks source link

Incorrect replacement of `override` with `member` #477

Closed simoncowen88 closed 5 years ago

simoncowen88 commented 5 years ago

Description

override can be replaced by member when it is not valid to do so.

Code

[<CustomEquality; NoComparison>]
type Foo =
    | Foo
    override __.Equals _ = false
    override __.GetHashCode () = 0

Result

[<CustomEquality; NoComparison>]
type Foo =
    | Foo
    member __.Equals _ = false
    member __.GetHashCode () = 0

This gives a compiler error of:

error FS0384: A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable'

(I'm currently behind a firewall that won't let me access http://ratatosk.dynu.net/fantomas - I can update with a link once I'm connected elsewhere if needed)

Options

Version: 3.0.0-beta-002

Name Value
IndentSpaceNum 4
PageWidth 120
PreserveEndOfLine false
SemicolonAtEndOfLine false
SpaceBeforeArgument true
SpaceBeforeColon false
SpaceAfterComma true
SpaceAfterSemicolon true
IndentOnTryWith false
ReorderOpenDeclaration false
SpaceAroundDelimiter true
KeepNewlineAfter false
StrictMode false
nojaf commented 5 years ago

Hey, this seems to be working for me. https://jindraivanek.gitlab.io/fantomas-ui/#?fantomas=preview-trivia&code=NoHgwgrgzgLg9gWwKIEcIEMA2BLGBPAbgAIA5OMRAB3QCdso4A7APgF0BYAKH0oFMiAYnDhEAvFyKSiAH0HCJUuADdeNOgBN+AfS0A6VBkxQiWsUQBmWKLwWTlqjdr0BxXjAAS6KAAsKmogAUAJRmAAxAA Unless I'm missing the point here.

simoncowen88 commented 5 years ago

A colleague mentioned this to me today, it appears to have been fixed on the trivia branch. It would be good to have a test to assert this continues to be the case as I couldn't find an issue/test related to this rather specific scenario (the interaction of attributes with overridden methods), suggesting that it may well currently be working by coincidence.

nojaf commented 5 years ago

We actually have one of those, https://github.com/fsprojects/fantomas/blob/d019e81ea4930c512861f4c1bb03b7fe84b5e1e2/src/Fantomas.Tests/InterfaceTests.fs#L137