Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Compiler Services incorrectly parses program

UPDATE:

I now realize that the question was stupid, I should have just filed the issue. In hindsight, I don't see why I even asked this question.
The issue is here: https://github.com/fsharp/FSharp.Compiler.Service/issues/544


Original question:

I'm using FSharp Compiler Services for parsing some F# code.
The particular piece of code that I'm facing right now is this:

  let f x y = x+y
  let g = f 1
  let h = (g 2) + 3

This program yields a TAST without the (+) call on the last line. That is, the compiler service returns TAST as if the last line was just let h = g 2.

The question is: is this is a legitimate bug that I ought to report or am I missing something?


Some notes

  1. Here is a repo containing minimal repro (I didn't want to include it in this question, because Compiler Services require quite a bit of dancing around).
  2. Adding more statements after the let h line does not change the outcome.
  3. When compiled to IL (as opposed to parsed with Compiler Services), it seems to work as expected (e.g. see fiddle)
  4. If I make g a value, the program parses correctly.
  5. If I make g a normal function (rather than partially applied one), the program parses correctly.
like image 781
Fyodor Soikin Avatar asked Mar 21 '16 18:03

Fyodor Soikin


1 Answers

I have no priori experience with FSharp.Compiler.Services but nevertheless I did a small investigation using Visual Studio's debugger. I analyzed abstract syntax tree of following string:

            """
              module X

              let f x y = x+y
              let g = f 1
              let h = (g 2) + 3
            """ 

I've found out that there's following object inside it:

App (Val (op_Addition,NormalValUse,D:\file.fs (6,32--6,33) IsSynthetic=false),TType_forall ([T1; T2; T3],TType_fun (TType_var T1,TType_fun (...,...))),...,...,...)

As you can see, there's an addition in 6th line between characters 32 and 33.

The most likely explanation why F# Interactive doesn't display it properly is a bug in a library (maybe AST is in an inconsistent state or pretty-printing is broken). I think that you should file a bug in project's issue tracker.

UPDATE:

Aforementioned object can be obtained in a debbuger in a following way:

error.[0] 
(option of Microsoft.FSharp.Compiler.SourceCodeServices.FSharpImplementationFileDeclaration.Entity) 
.Item2 
.[2]
(option of Microsoft.FSharp.Compiler.SourceCodeServices.FSharpImplementationFileDeclaration.MemberOrFunctionOrValue)
.Item3
.f (private member)
.Value
(option of Microsoft.FSharp.Compiler.SourceCodeServices.FSharpExprConvert.ConvExprOnDemand@903)
.expr
like image 124
Tomasz Maczyński Avatar answered Nov 13 '22 16:11

Tomasz Maczyński