Jump to page: 1 2
Thread overview
[Issue 15793] Change !is error to warning
Mar 12, 2016
Sobirari Muhomori
Mar 14, 2016
Jonathan M Davis
Mar 14, 2016
Sobirari Muhomori
Mar 14, 2016
Jonathan M Davis
Mar 15, 2016
Sobirari Muhomori
Mar 15, 2016
Jonathan M Davis
Mar 16, 2016
Sobirari Muhomori
Mar 16, 2016
Sobirari Muhomori
Dec 17, 2022
Iain Buclaw
March 12, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |regression

--
March 13, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com
           Severity|regression                  |enhancement

--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Some backstory:

Originally, if a was actually null, this would cause a segfault (it would try to call a.opEquals(null), which was a virtual call, etc.). This is why the error was added -- any usage of != null for classes/interfaces was never what you really wanted.

But with the current way object comparisons are done, != null would do the correct thing. I think actually, we can remove the error completely.

--
March 14, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #2 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
It's still more efficient to use is null or !is null, and it's what code really should be doing, but making it an error to use == null or != null is arguably a bit much.

--
March 14, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #3 from Sobirari Muhomori <dfj1esp02@sneakemail.com> ---
In reality I'm comparing COM interfaces. I removed the check, it was defensive anyway. That's my concern actually: such checks should be a no-brainer or it will cause very nasty consequences in the long run, so yeah, it's disturbing.

--
March 14, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #4 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
At this point, comparing null objects will work just fine, since the free function opEquals that calls the member function opEquals for classes checks for null first, but if you use is, you skip the call to opEquals entirely. So, the error is arguably forcing you to follow best practices, but if the error weren't there, the code would work just fine. It would just be slightly less efficient.

--
March 15, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #5 from Sobirari Muhomori <dfj1esp02@sneakemail.com> ---
The problem is not best practices, but usability.

--
March 15, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> ---
lowering != null to !is null is the right answer. I would be surprised if inlining doesn't automatically do this. But of course, the compiler rejects it, so no way to test it.

--
March 15, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #7 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
> The problem is not best practices, but usability.

As I said, while it's best practice to use is and !is with null, it is a bit much to treat it as an error to use == or !=. So, I'm not opposed to it being changed. I'm just pointing out that what it's telling you to do is what you really should be doing anyway. It's just being too forceful about it.

> lowering != null to !is null is the right answer.

That would be a good approach.

--
March 16, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

--- Comment #8 from Sobirari Muhomori <dfj1esp02@sneakemail.com> ---
A little comparison: in java and C# Object.Equals is provided, but not called implicitly. It's provided, but is opt-in and explicit, it's all somewhat rooted in java, C# and D just copied it. C# uses C++-style operator overloads, it's up to them to call Object.Equals or not. Also C# requires x.Equals(null) to always return false.

(In reply to Steven Schveighoffer from comment #6)
> lowering != null to !is null is the right answer.
That would be awesome.

--
March 16, 2016
https://issues.dlang.org/show_bug.cgi?id=15793

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
                URL|                            |https://dlang.org/spec/expr
                   |                            |ession.html

--
« First   ‹ Prev
1 2