Why is there no error when a library class is not supported on a platform

Hi. I just spent some time tracking down an error at run time, that it seems to me could have been caught at compile time. I was using std.net.Socket with a JavaScript target and got a run time reference error. Because the code passed through the compiler fine, I thought it couldn’t be that Socket isn’t supported with JavaScript is the platform. But it seems that that was exactly the problem. Is there a reason that the code compiles without error?

Here is the code

package ;

import sys.net.Socket;

class Main
{
    private var socket : Socket ;

    function new()
    {
        socket = new Socket() ;
    }

    static public function main()
    {
        var main = new Main();
    }
}

There is such error Try Haxe ! maybe it’s because libs that you use?

1 Like

That’s right! If I use -lib js-kit or -lib hxnodejs, there is no compile time error. But why is that?

You can use sys only on supported target(c++, php python node, c# Java, Lua and maybe more lol)