Can't "is null" an interface?!?! Incompatible types???

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Mar 8 06:13:58 UTC 2018


On Thursday, 8 March 2018 at 04:48:08 UTC, Nick Sabalausky 
(Abscissa) wrote:
> ---------------------
> import vibe.core.net;
> TCPConnection mySocket;
>
> void main() {
>     auto b = mySocket is null;
> }
> ---------------------
>
> That's giving me:
>
> ---------------------
> Error: incompatible types for (mySocket) is (null): 
> TCPConnection and typeof(null)
> ---------------------
>
> WTF?!?!
>
> The type in question (vibe.core.net.TCPConnection) is an 
> interface:
> http://vibed.org/api/vibe.core.net/TCPConnection
> https://github.com/vibe-d/vibe.d/blob/master/core/vibe/core/net.d#L344
>
> The following works just fine:
> ---------------------
> interface IFoo {}
>
> void main() {
>     IFoo i;
>     auto b = i is null;
> }
> ---------------------

That does seem odd.
---
/+dub.sdl:
dependency "vibe-d" version="~>0.8.3-alpha.1"
+/
import vibe.core.net;
import std.stdio;
TCPConnection mySocket;

void main() {
     auto b = mySocket is null;
     writeln(b);
}
---
works fine on run.dlang.io


More information about the Digitalmars-d-learn mailing list