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

Idempotency problem when adding members to a single case union without a pipe #3102

Closed
1 of 4 tasks
joprice opened this issue Aug 3, 2024 · 15 comments
Closed
1 of 4 tasks

Comments

@joprice
Copy link
Contributor

joprice commented Aug 3, 2024

Issue created from fantomas-online

Formatted code

module Test


type X = X
    with

        // a newline is added boave this line on each frmat if the union does not begin with a pipe
        static member x = 1

type Y =
    | Y

    static member x = 1

Reformatted code

module Test


type X = X
    with


        // a newline is added boave this line on each frmat if the union does not begin with a pipe
        static member x = 1

type Y =
    | Y

    static member x = 1

Problem description

Fantomas was not able to produce the same code after reformatting the result.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.
  • I would like a release if this problem is solved.
@nojaf
Copy link
Contributor

nojaf commented Aug 5, 2024

Hello, thanks for reporting this issue.

I believe the problem may be around:

+> onlyIfCtx (fun ctx -> ctx.Config.NewlineBetweenTypeDefinitionAndMembers) sepNln

Something along the lines of

onlyIfCtx
    (fun ctx -> ctx.Config.NewlineBetweenTypeDefinitionAndMembers)
    (sepNlnUnlessContentBefore (MemberDefn.Node members.[0]))

probably avoid the problem.

Are you interested in sending a PR for this?

@joprice
Copy link
Contributor Author

joprice commented Sep 9, 2024

Not yet familiar with the codebase but I can try it out and let you know if I don't get make progress.

@nojaf
Copy link
Contributor

nojaf commented Sep 9, 2024

We have some documentation about how the project is structured: https://fsprojects.github.io/fantomas/docs/contributors/Solution%20Structure.html

Let me know if you have any questions.

@joprice
Copy link
Contributor Author

joprice commented Sep 9, 2024

Nice. I checked out the project to make sure I can at least built it and get the test to success, but this test failed:

 Failed code that was invalid should be still be written [837 ms]
 Error Message:
    Assert.That(, )
 Expected: 0
 But was:  134

 Stack Trace:
    at FsUnit.TopLevelOperators.should[a,a](FSharpFunc`2 f, a x, Object actual)
  at Fantomas.Tests.Integration.ForceTests.code that was invalid should be still be written() in fantomas/src/Fantomas.Tests/Integration/ForceTests.fs:line 29

1)    at FsUnit.TopLevelOperators.should[a,a](FSharpFunc`2 f, a x, Object actual)
  at Fantomas.Tests.Integration.ForceTests.code that was invalid should be still be written() in fantomas/src/Fantomas.Tests/Integration/ForceTests.fs:line 29

Unrelated, but nice to start with a clean slate when modifying things. Is this one expected?

@joprice
Copy link
Contributor Author

joprice commented Sep 9, 2024

actually I missed an error above that that might be the cause

The active test run was aborted. Reason: Test host process crashed : Stack overflow.
Repeat 2 times:
--------------------------------
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
--------------------------------
   at [email protected](LinkExpr)
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>, Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Microsoft.FSharp.Primitives.Basics.List.map[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Microsoft.FSharp.Collections.ListModule.Map[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at [email protected](System.Tuple`2<Fantomas.FCS.Text.Range,Fantomas.FCS.Syntax.SynExpr>)
   at Fantomas.Core.ASTTransformer.mkTuple(CreationAide, Microsoft.FSharp.Collections.FSharpList`1<Fantomas.FCS.Syntax.SynExpr>, Microsoft.FSharp.Collections.FSharpList`1<Fantomas.FCS.Text.Range>, Fantomas.FCS.Text.Range)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkParenExpr(CreationAide, Fantomas.FCS.Text.Range, Fantomas.FCS.Syntax.SynExpr, Fantomas.FCS.Text.Range, Fantomas.FCS.Text.Range)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkParenExpr(CreationAide, Fantomas.FCS.Text.Range, Fantomas.FCS.Syntax.SynExpr, Fantomas.FCS.Text.Range, Fantomas.FCS.Text.Range)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at [email protected](System.Tuple`4<Microsoft.FSharp.Core.FSharpChoice`2<SingleTextNode,System.Tuple`2<Fantomas.FCS.Text.Range,Fantomas.FCS.Text.Range>>,Fantomas.FCS.Syntax.SynExpr,SingleTextNode,Fantomas.FCS.Syntax.SynExpr>)
   at Microsoft.FSharp.Primitives.Basics.List.map[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Microsoft.FSharp.Collections.ListModule.Map[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.collectComputationExpressionStatements(CreationAide, Fantomas.FCS.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Collections.FSharpList`1<ComputationExpressionStatement>,Microsoft.FSharp.Collections.FSharpList`1<ComputationExpressionStatement>>)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.collectComputationExpressionStatements(CreationAide, Fantomas.FCS.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Collections.FSharpList`1<ComputationExpressionStatement>,Microsoft.FSharp.Collections.FSharpList`1<ComputationExpressionStatement>>)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide, Fantomas.FCS.Syntax.SynExpr)

@nojaf
Copy link
Contributor

nojaf commented Sep 9, 2024

Ok, this is interesting. Are you on Mac? And does running dotnet test ./src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj work for you?

If it does, you could try and ignore this integration test. It did work for me locally. Not quite sure what went wrong.

@joprice
Copy link
Contributor Author

joprice commented Sep 9, 2024

I get the same error when running just the Fantomas.Core.Tests, so seems like something more general is wrong with my local env.

@joprice
Copy link
Contributor Author

joprice commented Sep 9, 2024

To narrow it down a little more,

  • Fantomas.Tests run but the integration test ForceTests fails
  • Fantomas.Client.Tests run fine,
  • Fantomas.Core.Tests stack overflow

Unfortunately, the last one seems to be where a test for this type of change is meant to go.

@nojaf
Copy link
Contributor

nojaf commented Sep 10, 2024

Please tell me again what you SDK version is? What operating system?
Can you use the dev container maybe?

@joprice
Copy link
Contributor Author

joprice commented Sep 10, 2024

I'm on arm mac with osx 14.5, dotnet version 8.0.303. I can try the devcontainer out.

@joprice
Copy link
Contributor Author

joprice commented Sep 10, 2024

It passes when run via a container with npx @devcontainers/cli up --workspace-folder . and npx @devcontainers/cli exec --workspace-folder . dotnet test.

@joprice
Copy link
Contributor Author

joprice commented Sep 10, 2024

I just tried running the build via dotnet fsi build.fsx -p Build and it passed without requiring the container. I noticed that it's running the tests under Release configuration. Running with Release: dotnet test src/Fantomas.Core.Tests -c Release does not stack overflow for me. I assume that the parser relies on some optimizations like tco that is only kicking in release mode. That allows me to run them locally without a container.

@nojaf
Copy link
Contributor

nojaf commented Sep 10, 2024

I'm not sure what is wrong with your environment but it feels like something is overriding <Tailcalls>true</Tailcalls> for you.

@nojaf
Copy link
Contributor

nojaf commented Sep 10, 2024

NuGet is acting weird,

image

@nojaf
Copy link
Contributor

nojaf commented Sep 10, 2024

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

No branches or pull requests

2 participants