Skip to content

Commit

Permalink
Stricter check for default interface member consumption in object exp…
Browse files Browse the repository at this point in the history
…ression.
  • Loading branch information
nojaf committed Nov 7, 2022
1 parent af38264 commit 18a97bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* Comment is removed when using array index access syntax, without a leading dot. [#2611](https://github.com/fsprojects/fantomas/issues/2611)
* Interface in object expression is not printed. [#2604](https://github.com/fsprojects/fantomas/issues/2604)

## [5.1.0] - 2022-11-04

Expand Down
21 changes: 21 additions & 0 deletions src/Fantomas.Core.Tests/InterfaceTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Fantomas.Core.Tests.InterfaceTests

open Microsoft.VisualStudio.TestPlatform.ObjectModel
open NUnit.Framework
open FsUnit
open Fantomas.Core.Tests.TestHelper
Expand Down Expand Up @@ -627,3 +628,23 @@ type IInterface2 =
type IInterface3 =
abstract member X: unit -> unit
"""

[<Test>]
let ``interface in obj expression, 2604`` () =
formatSourceString
false
"""
{ new IDisposable
interface Meh with
member x.Blur = () }
"""
config
|> prepend newline
|> should
equal
"""
{ new IDisposable
interface Meh with
member x.Blur = () }
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ and genExpr synExpr ctx =
isSmallExpression size smallExpression longExpression ctx

| ObjExpr(t, eio, withKeyword, bd, members, ims) ->
if List.isEmpty bd && List.isEmpty members then
if List.isEmpty bd && List.isEmpty members && List.isEmpty ims then
// Check the role of the second part of eio
let param = opt sepNone (Option.map fst eio) genExpr

Expand Down

0 comments on commit 18a97bd

Please sign in to comment.