HaxeFoundation / HaxeFoundation/haxe
Inconsistency in comparing nullable strings in Javascript
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
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:
```haxe
var dynamicString = new String("abc");
trace(dynamicString == "abc"); // prints 'true'
// this switch statement doesn't work as expected
switch (dynamicString) {
case "abc":
trace("doesn't print");
case "force js switch code":
trace("---");
}
// these workarounds do work
var abc = Std.string(dynamicString);
switch (abc) {
case "abc":
trace("Does print");
case "force js switch code":
trace("---");
}
var abc2 = "abc";
switch (dynamicString) {
case abc2:
trace("Does print");
case "force js switch code":
trace("---");
}
```
Contributor guide
Assessment
This issue has not been assessed yet.