Bug 36296 - Function returning funcion produces null references only via fsharpi
Summary: Function returning funcion produces null references only via fsharpi
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: Tools (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-26 16:29 UTC by Javier Villa
Modified: 2015-11-26 16:31 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
The test case ( fsharpi --use:bug6.fsx to examine values afterwards ) (240 bytes, application/octet-stream)
2015-11-26 16:29 UTC, Javier Villa
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 36296 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Javier Villa 2015-11-26 16:29:03 UTC
Created attachment 14010 [details]
The test case ( fsharpi --use:bug6.fsx to examine values afterwards )

It only happens through fsharpi. Running the code through mono's fhsarpc + mono program.exe or (Windows) .NET's fsi does not exhibit the defect.

let simpler arg0 =
    let innerFunc (arg1:string) =
        (arg0, arg1)
    innerFunc

let f1 = simpler 'A'
let f2 = simpler "B"
let f3 = simpler [3]

let val1 = f1 "f1"
let val2 = f2 "f2"
let val3 = f3 "f3"

When ran through fsi, an exception is produced and afterwards val2 and val3 have been set to null (but not val1):

$ fsharpi --use:bug6.fsx
 fsharpi
F# Interactive for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
(...)
> val2 ;;
val it : string * string = null
> val3 ;;
val it : int list * string = null

Exception:

--------------------------------------------------------

Exception raised during pretty printing.
Please report this so it can be fixed.
Trace: System.InvalidCastException: Cannot cast from source type to destination type.
  at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
  at Microsoft.FSharp.Compiler.Interactive.Shell+Utilities+AnyToLayoutSpecialization`1[Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[System.String,System.String]]].Microsoft-FSharp-Compiler-Interactive-Shell-Utilities-IAnyToLayoutCall-FsiAnyToLayout (Internal.Utilities.StructuredFormat.FormatOptions options, System.Object o) [0x00000] in <filename unknown>:0 
  at Microsoft.FSharp.Compiler.Interactive.Shell+FsiValuePrinter.PrintValue (Microsoft.FSharp.Compiler.Interactive.FsiValuePrinterMode printMode, Internal.Utilities.StructuredFormat.FormatOptions opts, System.Object x, System.Type ty) [0x00000] in <filename unknown>:0 


Exception raised during pretty printing.
Please report this so it can be fixed.
Trace: System.InvalidCastException: Cannot cast from source type to destination type.
  at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
  at Microsoft.FSharp.Compiler.Interactive.Shell+Utilities+AnyToLayoutSpecialization`1[Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[System.Int32],System.String]]].Microsoft-FSharp-Compiler-Interactive-Shell-Utilities-IAnyToLayoutCall-FsiAnyToLayout (Internal.Utilities.StructuredFormat.FormatOptions options, System.Object o) [0x00000] in <filename unknown>:0 
  at Microsoft.FSharp.Compiler.Interactive.Shell+FsiValuePrinter.PrintValue (Microsoft.FSharp.Compiler.Interactive.FsiValuePrinterMode printMode, Internal.Utilities.StructuredFormat.FormatOptions opts, System.Object x, System.Type ty) [0x00000] in <filename unknown>:0 

---------------------------------------------------

If a printfn "%A" innerFn is added at the end of the "simpler" function to show the
result value, something interesting is shown for the problematic cases:

First line is for the OK function: (the same line for the 3 of them when using Windows' .NET fsi)
> <fun:innerFunc@3>

Then a crash with the following output:
Microsoft.FSharp.Core.PrintfFormat`5[Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[System.String,System.String]],Microsoft.FSharp.Core.Unit],System.IO.TextWriter,Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[System.String,System.String]]]
Microsoft.FSharp.Core.PrintfFormat`5[Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[System.Int32],System.String]],Microsoft.FSharp.Core.Unit],System.IO.TextWriter,Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[System.Int32],System.String]]]
Comment 1 Javier Villa 2015-11-26 16:31:55 UTC
Some version info:

Linux (Ubuntu 14.04) kernel 3.13.0-68-generic

mono-runtime  4.0.5.1-0xamarin1   amd64 Mono runtime - default version
fsharp 4.0.0.3-0xamarin1 all functional-first programming language - compiler for the CLI