-
Notifications
You must be signed in to change notification settings - Fork 847
Open
Labels
Area-Compiler-OptimizationThe F# optimizer, release code gen etc.The F# optimizer, release code gen etc.Feature Request
Milestone
Description
The Hash function returns always returns 0 for null values in C#, but in F# calling the hash function with a null value can result in a NullReferenceException.
I discovered it while working on #2096. When the GetHashCode function is small enough in size, it causes the Hash function to return 0 in debug mode and not a NullReferenceException .
Repro steps
- Create an F# library:
module Test
type Class1 = A |B
let test = Operators.hash (Unchecked.defaultof<Class1>)
- Create a C# console application with the following code:
using Microsoft.FSharp.Core;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Test.Class1 a = null;
System.Console.WriteLine(Operators.Hash(a));
System.Console.WriteLine(Test.test);
}
}
}
-
Reference the F# library created in step 1 in the C# application created in step 2.
-
Build/Run the solution in Release or Debug configuration with any bitness.
Expected behavior
The same result is printed twice.
Actual behavior
The output is 0 for the first line followed by a NullReferenceException
Known workarounds
None.
Related information
Provide any related information
- Operating system: Windows 10
- Branch: F# 4.0 and master
- .NET Runtime, CoreCLR or Mono Version: .NET 4.6
- Editing Tools (e.g. Visual Studio Version): Visual Studio 2015
Metadata
Metadata
Assignees
Labels
Area-Compiler-OptimizationThe F# optimizer, release code gen etc.The F# optimizer, release code gen etc.Feature Request
Type
Projects
Status
In Progress