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

Reset IsFirstChild of ASTContext before printing interface members. #1670

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/Fantomas.Tests/InterfaceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,95 @@ let test () =
{ new IDisposable with
override this.Dispose() = dispose somethingElse }
"""

[<Test>]
let ``attribute before interface member, 1668`` () =
formatSourceString
false
"""
type internal WorkingShard =
| Started of ReactoKinesixShardProcessor
| Stopped of StoppedReason

and ReactoKinesixApp
private
(
kinesis: IAmazonKinesis,
dynamoDB: IAmazonDynamoDB,
appName: string,
streamName: string,
workerId: string,
processorFactory: IRecordProcessorFactory,
config: ReactoKinesixConfig
) as this =


interface IReactoKinesixApp with
[<CLIEvent>] member this.OnInitialized = initializedEvent.Publish
[<CLIEvent>] member this.OnBatchProcessed = batchProcessedEvent.Publish
"""
config
|> prepend newline
|> should
equal
"""
type internal WorkingShard =
| Started of ReactoKinesixShardProcessor
| Stopped of StoppedReason

and ReactoKinesixApp
private
(
kinesis: IAmazonKinesis,
dynamoDB: IAmazonDynamoDB,
appName: string,
streamName: string,
workerId: string,
processorFactory: IRecordProcessorFactory,
config: ReactoKinesixConfig
) as this =


interface IReactoKinesixApp with
[<CLIEvent>]
member this.OnInitialized = initializedEvent.Publish

[<CLIEvent>]
member this.OnBatchProcessed = batchProcessedEvent.Publish
"""

[<Test>]
let ``recursive type where second type has interface with attributes on the members`` () =
formatSourceString
false
"""
type Foo = | Foo of string

and Bar =
interface IMeh with
[<SomeAttribute>] member this.Value = ()
[<SomeAttribute>] member this.ValueWithReturnType : unit = ()
[<SomeAttribute>] member this.SomeFunction (a: int) = 4 + a
[<SomeAttribute>] member this.SomeFunctionWithReturnType (a: int) : int = a + 5
"""
config
|> prepend newline
|> should
equal
"""
type Foo = Foo of string

and Bar =
interface IMeh with
[<SomeAttribute>]
member this.Value = ()

[<SomeAttribute>]
member this.ValueWithReturnType : unit = ()

[<SomeAttribute>]
member this.SomeFunction(a: int) = 4 + a

[<SomeAttribute>]
member this.SomeFunctionWithReturnType(a: int) : int = a + 5
"""
3 changes: 3 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,9 @@ and genMemberDefn astContext node =
+> sepNln
+> genMemberDefnList
{ astContext with
// Reset this property to avoid problems with the generation of the attributes on the members
// See 1668
IsFirstChild = true
InterfaceRange = Some range }
mds
+> unindent)
Expand Down