Explain Cannot access private field in if statement but OK in switch case

Can someone explain why I get “Cannot access private field” in a if statement but it’s OK in switch case statement.

This produces an error:

if (currDeviceName == Ipad.SHOE) dragTargetNum = 640;

This does not:

switch (currDeviceName) {
case Ipad.SHOE:
dragTargetNum = 640;

That should be more of a haxe issue but I can’t recreate the issue


no matter how I try to access the private value it fails

edit: Just had an after thought: Maybe “currDeviceName” can never be equal to “Ipad.SHOE”? (for example, they are different enums). In that case the switch is smart enough to realize that your particular case will never happen and doesn’t throw the compilation error?

Was able to fix it. In my class Ipad, SHOE was declared as a private static inline var. I changed that to a public static inline var and it worked.

But this also means that for some reason, when I do a build in Visual Studio Code (lime build html5) the compiler used allows access in a switch case to a private var from another class when it shouldn’t.

Not sure who I should report this bug to.