Bug 956 – Testing Class Object for null reference causes Access Violation Error

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-02-13T07:03:00Z
Last change time
2014-02-16T15:26:05Z
Assigned to
bugzilla
Creator
hennrich.bloebaum

Comments

Comment #0 by hennrich.bloebaum — 2007-02-13T07:03:25Z
class MyClass { } void main() { MyClass[] myArray = null; MyClass myObject = null; if(!myArray) { // Ok } if(myArray == null) { // Works on dynamic arrays } if(!myObject) { // Ok } if(myObject == null) { // Error: Access Violation } }
Comment #1 by ddparnell — 2007-02-13T08:20:03Z
Not a bug. The form "object == null" gets transformed as object.opEquals(null), and so if the object is actually null already, the invocation of it's opEquals member fails. The documented method of testing for null objects is if (object is null) ...