haxe-objc-target icon indicating copy to clipboard operation
haxe-objc-target copied to clipboard

String equality is broken

Open zeen opened this issue 11 years ago • 5 comments

All strings are separate copies, so '==' checks break.

e.g.,

private function test() {
    var x = "hello";
    var t = (x == "hello");
    return t ? "Good" : "Bad";
}

generates this Objective-C:

- (NSMutableString*) test{
    NSMutableString *x = [@"hello" mutableCopy];
    BOOL t = x == [@"hello" mutableCopy];
    return ( (t) ? [@"Good" mutableCopy] : [@"Bad" mutableCopy]);
}

i.e., it returns Bad, because both instances of "hello" are separate copies, and '==' is false.

The fix for this would either be string interning, or using NSString.isEqualToString.

zeen avatar Jun 27 '13 19:06 zeen