Open EddieCameron opened 4 years ago
(I'm new to Haxe, please forgive my confusion about dynamic vs nullable terminology)
That's tragic, but I don't really see what we could do about it if JavaScript behaves like that...
Yeah it's a bit specific JS quirk. new String(...)
"boxes" the string so it loses strict equality (which is used for switch
in JS) with other strings. One solution would to add .toString()
to the switch subjects that are String, but it looks pretty awkward and is really only ever needed for this particular edge-case.
Also FYI, case abc2:
in this case is not what you think it is, it's a pattern variable capture, not a comparison against local variable named abc2
.
Ha, I thought case abc2
seemed unusual...
So if JS uses strict equality for all switch comparisons, would this happen with boxed basic types as well? Does haxe use non-strict comparison for any other types? (like how C# structs use member-wise equality)
Haxe generally knows how to compare strings constructed with
var myStringA = new String("blah")
and strings constructed with `var myStringB = "blah", and will treat them equally.However in a switch statement (at least in Javascript), these will not be equal: