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

Pipe is removed when DU type name matches record type name #641

Closed
JonCanning opened this issue Jan 13, 2020 · 3 comments · Fixed by #647
Closed

Pipe is removed when DU type name matches record type name #641

JonCanning opened this issue Jan 13, 2020 · 3 comments · Fixed by #647

Comments

@JonCanning
Copy link

Issue created from fantomas-ui

Pipe is removed when DU type name matches record type name

Code

type Record =
    { Name: string }

type DU = | Record

Result

type Record =
    { Name: string }

type DU = Record

Options

Fantomas 3.1.0

Name Value
IndentOnTryWith false
IndentSpaceNum 4
KeepNewlineAfter false
MaxIfThenElseShortWidth 40
PageWidth 120
ReorderOpenDeclaration false
SemicolonAtEndOfLine false
SpaceAfterComma true
SpaceAfterSemicolon true
SpaceAroundDelimiter true
SpaceBeforeArgument true
SpaceBeforeColon false
StrictMode false
@nojaf
Copy link
Contributor

nojaf commented Jan 13, 2020

This is by design actually. See https://jindraivanek.gitlab.io/fantomas-ui/#?fantomas=preview&code=C4TwDgpgBAIgqlAvFAPlAShAxgewE4AmQA
You don't need the pipe when you only have one clause.

If preferred you can open a new change request to maybe introduce a setting whether the pipe should be there for single case DUs.

@nojaf nojaf closed this as completed Jan 13, 2020
@JonCanning
Copy link
Author

In my example it becomes a type alias for Record rather than a single case DU

@nojaf
Copy link
Contributor

nojaf commented Jan 13, 2020

Apologies, I missed the point of the issue I'm afraid 😅
The AST is indeed different before and after:

ImplFile
  (ParsedImplFileInput
     ("Script.fsx",true,QualifiedNameOfFile Script$fsx,[],[],
      [SynModuleOrNamespace
         ([Script],false,AnonModule,
          [Types
             ([TypeDefn
                 (ComponentInfo
                    ([],[],[],[Record],
                     PreXmlDoc ((1,11),FSharp.Compiler.Ast+XmlDocCollector),
                     false,None,Script.fsx (1,5--1,11) IsSynthetic=false),
                  Simple
                    (Record
                       (None,
                        [Field
                           ([],false,Some Name,
                            LongIdent (LongIdentWithDots ([string],[])),false,
                            PreXmlDoc
                              ((1,20),FSharp.Compiler.Ast+XmlDocCollector),None,
                            Script.fsx (1,16--1,28) IsSynthetic=false)],
                        Script.fsx (1,14--1,30) IsSynthetic=false),
                     Script.fsx (1,14--1,30) IsSynthetic=false),[],
                  Script.fsx (1,5--1,30) IsSynthetic=false)],
              Script.fsx (1,0--1,30) IsSynthetic=false);
           Types
             ([TypeDefn
                 (ComponentInfo
                    ([],[],[],[DU],
                     PreXmlDoc ((2,7),FSharp.Compiler.Ast+XmlDocCollector),false,
                     None,Script.fsx (2,5--2,7) IsSynthetic=false),
                  Simple
                    (Union
                       (None,
                        [UnionCase
                           ([],Record,UnionCaseFields [],
                            PreXmlDoc
                              ((2,11),FSharp.Compiler.Ast+XmlDocCollector),None,
                            Script.fsx (2,12--2,18) IsSynthetic=false)],
                        Script.fsx (2,10--2,18) IsSynthetic=false),
                     Script.fsx (2,10--2,18) IsSynthetic=false),[],
                  Script.fsx (2,5--2,18) IsSynthetic=false)],
              Script.fsx (2,0--2,18) IsSynthetic=false)],PreXmlDocEmpty,[],None,
          Script.fsx (1,0--2,18) IsSynthetic=false)],(true, true)))

after:

ImplFile
  (ParsedImplFileInput
     ("Script.fsx",true,QualifiedNameOfFile Script$fsx,[],[],
      [SynModuleOrNamespace
         ([Script],false,AnonModule,
          [Types
             ([TypeDefn
                 (ComponentInfo
                    ([],[],[],[Record],
                     PreXmlDoc ((1,11),FSharp.Compiler.Ast+XmlDocCollector),
                     false,None,Script.fsx (1,5--1,11) IsSynthetic=false),
                  Simple
                    (Record
                       (None,
                        [Field
                           ([],false,Some Name,
                            LongIdent (LongIdentWithDots ([string],[])),false,
                            PreXmlDoc
                              ((1,20),FSharp.Compiler.Ast+XmlDocCollector),None,
                            Script.fsx (1,16--1,28) IsSynthetic=false)],
                        Script.fsx (1,14--1,30) IsSynthetic=false),
                     Script.fsx (1,14--1,30) IsSynthetic=false),[],
                  Script.fsx (1,5--1,30) IsSynthetic=false)],
              Script.fsx (1,0--1,30) IsSynthetic=false);
           Types
             ([TypeDefn
                 (ComponentInfo
                    ([],[],[],[DU],
                     PreXmlDoc ((2,7),FSharp.Compiler.Ast+XmlDocCollector),false,
                     None,Script.fsx (2,5--2,7) IsSynthetic=false),
                  Simple
                    (TypeAbbrev
                       (Ok,LongIdent (LongIdentWithDots ([Record],[])),
                        Script.fsx (2,10--2,16) IsSynthetic=false),
                     Script.fsx (2,10--2,16) IsSynthetic=false),[],
                  Script.fsx (2,5--2,16) IsSynthetic=false)],
              Script.fsx (2,0--2,16) IsSynthetic=false)],PreXmlDocEmpty,[],None,
          Script.fsx (1,0--2,16) IsSynthetic=false)],(true, true)))

So I guess single case DU without any UnionCaseFields should also have a pipe.

Thanks for this report!

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

Successfully merging a pull request may close this issue.

2 participants