Open
Description
Repro steps
Write the following F# program, and run it:
let inline toString (x: ^a) =
(^a : (member ToString : unit -> string) x)
[<EntryPoint>]
let main argv =
let s = toString 123
printfn "%s" s
0
Expected behavior
This program should print a string 123
.
Actual behavior
This program throws a NullReferenceException
:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Program.main(String[] argv) in T:\Temp\ConsoleApp12\ConsoleApp12\Program.fs:line 6
It works on reference types though.
Known workarounds
Do not use an inline function there.
Related information
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
New