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

Fantomas errors out on new Foo "" #1363

Closed
Smaug123 opened this issue Jan 12, 2021 · 1 comment · Fixed by #1369
Closed

Fantomas errors out on new Foo "" #1363

Smaug123 opened this issue Jan 12, 2021 · 1 comment · Fixed by #1369

Comments

@Smaug123
Copy link
Contributor

I was unable to submit this bug using the online tool ("request too large"), but it does reproduce there.

The following is valid F#:

open System.IO
let f = new StringReader ""

However, Fantomas throws with the following:

System.Exception: Unexpected expression: New
  (false, LongIdent (LongIdentWithDots ([StringReader], [])),
   Const
     (String ("", tmp.fsx (2,25--2,27) IsSynthetic=false),
      tmp.fsx (2,25--2,27) IsSynthetic=false),
   tmp.fsx (2,8--2,27) IsSynthetic=false)
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1433.Invoke(String message) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1433
   at Fantomas.CodePrinter.genExpr(ASTContext astContext, SynExpr synExpr, Context ctx) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2565
   at Fantomas.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 782
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 441
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 441
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 441
   at Fantomas.Context.expressionExceedsPageWidth(FSharpFunc`2 beforeShort, FSharpFunc`2 afterShort, FSharpFunc`2 beforeLong, FSharpFunc`2 afterLong, FSharpFunc`2 expr, Context ctx) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 893
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 441
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 526
   at Fantomas.CodePrinter.genImpFile@96-6.Invoke(Context ctx) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 96
   at Fantomas.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 441
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FSharpList`1 hashTokens, FormatContext formatContext, FormatConfig config) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 395
   at Fantomas.CodeFormatterImpl.format@409-1.Invoke(Tuple`3[] _arg1) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 411
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 404
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104

Arguably it should be formatted new StringReader (""); certainly I seem to remember that it's not always valid to omit the parentheses (or, indeed, the space - though I don't know why I seem to remember those).

@Smaug123
Copy link
Contributor Author

We can (and probably should!) work around this ourselves in the code we're trying to format, by changing the code to new StringReader(""). I just raised it because it's a bug; it's not very important.

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