Skip to content

(=) and (<>) throw NullReferenceExceptions when left operand is null #3108

@simoncowen88

Description

@simoncowen88

(=) and (<>) operators handle left operand being null incorrectly - throwing a NullReferenceException.
This is particularly unexpected, and makes these operators non-reflexive.

Repro steps

type Foo = Foo
let nullFoo = Unchecked.defaultof<Foo>

Foo = nullFoo // false - as expected
nullFoo = Foo // throws a NullReferenceException

Foo <> nullFoo // true - as expected
nullFoo <> Foo // throws a NullReferenceException

Expected behavior

(=) and (<>) operators should be reflexive.

Actual behavior

When the left operand of / first argument to the operator is null, a NullReferenceException is thrown.

Known workarounds

System.Object.Equals has the expected behaviour as described above.

Related information

Provide any related information

  • Windows 7
  • .NET 4.6.1
  • F# 4.0
  • Severity : within F# this is a relatively minor issue as you are unlikely to encounter null instances, however in interop scenarios this is fairly painful and, I would argue, extremely unexpected behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-LibraryIssues for FSharp.Core not covered elsewhere

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions