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

Crash when trying to format indexed property with three arguments. #2971

Closed
gubser opened this issue Nov 1, 2023 · 2 comments · Fixed by #2974
Closed

Crash when trying to format indexed property with three arguments. #2971

gubser opened this issue Nov 1, 2023 · 2 comments · Fixed by #2974

Comments

@gubser
Copy link

gubser commented Nov 1, 2023

I tried to create an issue using fantomas-online but GitHub reported 'Your request URL is too long.'.

Here's the link using preview version: fantomas-online

Code

type MyArray3 () = 
    member _.Item
        with get (x: int, y: int, z: int) =
            ()
        and set (x: int, y: int, z: int) v =
            ()

Result

System.ArgumentException: The lists had different lengths.
list1 is 1 element shorter than list2 (Parameter 'list1')
   at Microsoft.FSharp.Core.DetailedExceptions.invalidArgDifferentListLength[?](String arg1, String arg2, Int32 diff) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 26
   at Microsoft.FSharp.Primitives.Basics.List.zipToFreshConsTail[a,b](FSharpList`1 cons, FSharpList`1 xs1, FSharpList`1 xs2) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 906
   at Microsoft.FSharp.Primitives.Basics.List.zip[T1,T2](FSharpList`1 xs1, FSharpList`1 xs2) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 923
   at Microsoft.FSharp.Collections.ListModule.Zip[T1,T2](FSharpList`1 list1, FSharpList`1 list2) in D:\a\_work\1\s\src\FSharp.Core\list.fs:line 598
   at Fantomas.Core.ASTTransformer.mkTuplePat(CreationAide creationAide, FSharpList`1 pats, FSharpList`1 commas, Range m) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1625
   at Fantomas.Core.ASTTransformer.mkPat(CreationAide creationAide, SynPat p) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1709
   at Fantomas.Core.ASTTransformer.pats@2683.Invoke(SynPat p)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 243
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\FSharp.Core\list.fs:line 96
   at Fantomas.Core.ASTTransformer.mkPropertyGetSetBinding(CreationAide creationAide, FSharpOption`1 accessibility, SingleTextNode leadingKeyword, SynBinding binding) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2683
   at Fantomas.Core.ASTTransformer.mkMemberDefn(CreationAide creationAide, SynMemberDefn md) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2893
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 243
   at Fantomas.Core.ASTTransformer.mkTypeDefn(CreationAide creationAide, SynTypeDefn _arg13) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2619
   at Fantomas.Core.ASTTransformer.mkModuleDecls(CreationAide creationAide, FSharpList`1 decls, FSharpFunc`2 finalContinuation) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3052
   at Fantomas.Core.ASTTransformer.mkModuleOrNamespace(CreationAide creationAide, SynModuleOrNamespace mn) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3136
   at Fantomas.Core.ASTTransformer.mds@3146.Invoke(SynModuleOrNamespace mn)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 243
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\FSharp.Core\list.fs:line 96
   at Fantomas.Core.ASTTransformer.mkImplFile(CreationAide creationAide, ParsedImplFileInput _arg15, Range m) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3146
   at Fantomas.Core.ASTTransformer.mkOak(FSharpOption`1 sourceText, ParsedInput ast) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3571
   at Fantomas.Core.CodeFormatterImpl.formatAST(ParsedInput ast, FSharpOption`1 sourceText, FormatConfig config, FSharpOption`1 cursor) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 66
   at Fantomas.Core.CodeFormatterImpl.formatDocument@89-3.Invoke(Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 89
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 508
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112

Problem description

Fantomas fails to format indexed property with three variables. But it works with two variabels, see fantomas-online

Extra information
[ ] The formatted result breaks my code.
[ ] The formatted result gives compiler warnings.
[x] I or my company would be willing to help fix this.
[x] I would like a release if this problem is solved.

@gubser gubser changed the title Fantomas crashes when trying to format indexed property with three arguments. Crash when trying to format indexed property with three arguments. Nov 1, 2023
@nojaf
Copy link
Contributor

nojaf commented Nov 2, 2023

Hello, thank you for this report.
I took a look and found a solution to this problem.
The short version is that the AST the parser produces is rather misleading.
We had a workaround for this but never considered any cases where there are more than 2 elements in the tuple.

@nojaf
Copy link
Contributor

nojaf commented Nov 2, 2023

Fix available in https://www.nuget.org/packages/fantomas/6.2.3

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

Successfully merging a pull request may close this issue.

2 participants