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

Error in formatting nested else if construction #675

Closed
nojaf opened this issue Feb 8, 2020 · 0 comments · Fixed by #678
Closed

Error in formatting nested else if construction #675

nojaf opened this issue Feb 8, 2020 · 0 comments · Fixed by #678

Comments

@nojaf
Copy link
Contributor

nojaf commented Feb 8, 2020

Issue created from fantomas-ui

Please describe here fantomas problem you encountered

Code

namespace Fantomas

module String =
    let merge a b =
            if la <> lb then 
                if la > lb then a' else b'
            else
                if String.length a' < String.length b' then a' else b' 

Error

Exception: Unexpected scenario when formatting else if / elif, please open an issue via https://jindraivanek.gitlab.io/fantomas-ui Stack Trace:    at Fantomas.TriviaContext.else if / elif(range rangeOfIfThenElse, Context ctx)
   at Fantomas.CodePrinter.genElifOneliner@1211-2.Invoke(Context x)
   at Fantomas.CodePrinter.genElifOneliner@1211-3.Invoke(Context x)
   at Fantomas.CodePrinter.genElifOneliner@1212-5.Invoke(Context x)
   at Fantomas.CodePrinter.genElifOneliner@1213-6.Invoke(Context x)
   at Fantomas.CodePrinter.genElifOneliner@1214-8.Invoke(Context x)
   at Fantomas.CodePrinter.genElifOneliner@1215-9.Invoke(Context x)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx)
   at Fantomas.Context.colPost[T](FSharpFunc`2 f2, FSharpFunc`2 f1, IEnumerable`1 c, FSharpFunc`2 f, Context ctx)
   at Fantomas.CodePrinter.genExpr@1324-324.Invoke(Context x)
   at Fantomas.Context.atIndentLevel@176-6.Invoke(Context x)
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.Context.futureNlnCheckMem@412-1.Invoke(Tuple`2 tupledArg)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Fantomas.Cache.memoizeBy@91.Invoke(a x)
   at Fantomas.Context.futureNlnCheck(FSharpFunc`2 f, Context ctx)
   at Fantomas.CodePrinter.genExprSepEqPrependType(ASTContext astContext, FSharpFunc`2 prefix, SynPat pat, SynExpr e, Context ctx)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.CodePrinter.genModuleDecl@331-46.Invoke(Context x)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.CodePrinter.genTrivia@2268-1.Invoke(Context x)
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx)
   at Fantomas.CodePrinter.genImpFile@79-6.Invoke(Context ctx)
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FormatContext formatContext, FormatConfig config)
   at Fantomas.CodeFormatterImpl.format@406-1.Invoke(Tuple`2[] _arg1)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 416
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 349
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 870
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 890
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 1153
   at Server.Result.attempt[a](FSharpFunc`2 f) in /build/src/Server/Server.fs:line 24

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 added a commit to nojaf/fantomas that referenced this issue Feb 14, 2020
nojaf added a commit to nojaf/fantomas that referenced this issue Feb 14, 2020
nojaf added a commit that referenced this issue Feb 15, 2020
…lseExpression range (#678)

* Updated month in release notes

* Adding failing test for #675.

* Fix SynExpr.IfThenElse when the else keyword is not included in the elseExpression range. Fixes #675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant